| « Microscope Camera | Docker example of creating simple dockerized app » |
Docker miscellaneous commands (cheatsheet)
This command lists out the local images stored on your docker server
docker images
This command searches the docker repository. Note that the highest rated (starred) images are listed at the top
docker search <search text>
This command will pull the image from the docker repository to your docker server
docker pull <image name>
This command will remove a docker image
docker rmi <image name>
This command will show *all* docker containers (running or not)
docker ps -a
This command will remove a docker container
docker rm <container name>
This command will display a ton of information about a container - including the IP address
docker inspect <container name>
docker inspect <container name> | grep IP
This will start up a docker container with port mapping - the host port will be chosen randomly
docker run -d -p 8080 <image name>
This will start up a docker container with directory mapping
docker run -d -v /path/on/host:/path/in/container
This will start up a docker container with port forwarding - the port will be assigned
docker run -d -p <host port>:<docker port> <image name>
docker run -d -p 8000:8080 <image name>
docker run -d -p 8000:8080 -p 8001:8080 <image name>
This will start up a docker container in host mode (use the ip address of the host and open the ports from the container on the host directly)
docker run -d --net=host <image name>
This will start up a docker container and specify the container name
docker run -d --name <container name>
There are multiple ways to connect to the container. Attach is not recommended as it relies on the container actually running a shell.
docker attach
docker exec -i -t <container name> bash
You can attach to containers, make changes and create a new image by using the commit command (recommend to prefix the image with "my" or initials)
docker commit <current container name> <new image name>
This will build a docker image from a Dockerfile in the current directory
docker build -t <image name> .