Skip to content

Instantly share code, notes, and snippets.

@64lines
Last active April 29, 2020 02:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save 64lines/d5df808d296c19892fe4c900b81136e5 to your computer and use it in GitHub Desktop.
Save 64lines/d5df808d296c19892fe4c900b81136e5 to your computer and use it in GitHub Desktop.
[DOCKER] Docker Useful Commands

Useful Docker commands

docker build -t friendlyname .                                       # Create image using this directory's Dockerfile
docker run -p 4000:80 friendlyname                                   # Run "friendlyname" mapping port 4000 to 80
docker run -d -p 4000:80 friendlyname                                # Same thing, but in detached mode
docker run -d -p 4000:80 -n containername friendlyname               # With the container name
docker run -dit --name apache2 apache2                               # Run in the background
docker ps                                                            # See a list of all running containers
docker stop <hash>                                                   # Gracefully stop the specified container
docker start <hash>                                                  # Gracefully start the specified container
docker ps -a                                                         # See a list of all containers, even the ones not running
docker kill <hash>                                                   # Force shutdown of the specified container
docker rm <hash>                                                     # Remove the specified container from this machine
docker rm $(docker ps -a -q)                                         # Remove all containers from this machine
docker images -a                                                     # Show all images on this machine
docker rmi <imagename>                                               # Remove the specified image from this machine
docker rmi $(docker images -q)                                       # Remove all images from this machine
docker login                                                         # Log in this CLI session using your Docker credentials
docker tag <image> username/repository:tag                           # Tag <image> for upload to registry
docker push username/repository:tag                                  # Upload tagged image to registry
docker run username/repository:tag                                   # Run image from a registry
docker exec -i -t containerId bash                                   # Get into the container Jay!
docker run -ti --entrypoint /bin/sh ubuntu                           # Run a container with a specific image
docker ps -a -q --filter ancestor=headsup-file-monitoring            # Stop docker container by name
docker logs 8800331236b5                                             # Show the container logs using its container ID
docker inspect 73233db4d546 | grep IPAddress                         # Get the IP address using the container ID
docker start 73233db4d546                                            # Start a container without passing through all its installation
docker ps -a                                                         # It shows all the containers installed in the system

Show listening ports on Windows

netstat -ano | grep 5432
netstat -vatn | grep 3306
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment