Commonly used Docker Commands

Listed below are some of the most commonly used Docker commands. For a complete list of commands search Docker. These are the Docker commands that the team has found most useful.

Commands to Navigating the Docker Environment:

  • docker images –all = show all images
  • docker ps -s = to get a list of containers
  • docker logs -f = to tail the container logs
  • docker exec -it “containername” geth –help = to run a Geth help command in docker
  • docker exec -it “containername” ls = to look at file system
  • docker exec -it “containername”/bin/bash = Allows one to navigate to the filesystem in the container

Commands to Monitor the Docker Environment:

  • docker container stats = To see statistics of the Docker container environment

To Run / Start a Docker image:

  • docker run -i -t = to run a image
  • docker run -d -p 80:80 docker/getting-started – = -d – run the container in detached mode (in the background).-p 80:80 – map port 80 of the host to port 80 in the container
  • docker run -dp 3000:3000 containername = to start the container
  • docker stop = Use the docker stop command to stop the container
  • docker rm = Once the container has stopped, you can remove it by using the docker rm command.

Commands to Clean up Docker Images and Containers:

  • docker system prune
  • docker container prune
  • docker image prune -a

To Push an Image to Docker Hub:

  • build in pycharm or IDE
  • tag it
  • docker push userID/project:tagname

To Pull an Image from Docker:

  • docker save -o C:\Users\PC\PycharmProjects\projectname.tar projectName
  • The command above saves an image in the pycharm directory.
  • ProjectName is the name of the image that you want to save

To Build a Container from an Image in Docker:

  • docker build -t file/projectname = to build a container image

Docker Utilities Commands

  • dig mysql – Inside the container, we’re going to use the dig command, which is a useful DNS tool. We’re going to look up the IP address for the hostname mysql http://localhost/tutorial/multi-container-apps/
  • docker attach the-container-id = to attach your terminal’s standard input, output, and error (or any combination of the three) to a running container using the container’s ID or name.
  • docker inspect -f ‘{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}’ GETH – get the ip address of the GETH container
  • docker inspect -f ‘{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}’ container_name_or_id

Additional Resources

Next – Docker container built in Windows then deployed to a Linux environment

2 thoughts on “Commonly used Docker Commands

Leave a Reply