docker commands for local development
Hi Guys, here I will be keeping all the docker commands that I run/need while working on local machine.
I will be adding more commands as well, so stay tuned.
To clear all the dangling/exit containers
docker system prune
To Spun local PostgresDB for testing
docker run -d \
-p 5432:5432 \
-e "POSTGRES_USER=scott" \
-e "POSTGRES_DB=sample_db" \
-e "POSTGRES_PASSWORD=tiger" \
postgres:9.6
To Build the docker image and re-tag it
docker build -t img_name .
docker tag img_name git.com/username/imagename
To Run Docker image locally and expose its port
docker run -p 8081:8080 image_name
Above command will run the docker image and will shows logs from container in same terminal(and you terminal will be occupied and container will be closed when you close the terminal)
You can also pass “-d” parameter to run it in the background(detached mode)
docker run -p 8081:8080 -d image_name
once container running in background, you can use following command to stop
docker stop container_hash
docker rm container_hash
// or you can force remove without stopping container
docker rm -f container_hash
Once container started, its given random container name(uuid), you can avoid that and give your container some meaningful name as well with following docker command.
docker run -p 8081:8080 -d --name awesome_app image_name
Now, you can use this “awesome_app” name to remove container or perform some other task.
Please do suggest any other command that you are using in your workflow
Thanks for reading