Docker Cheatsheet

1
2
3
4
5
docker run name:latest

# Run a docker image in foreground. latest is a tag.
#Port forwarding. Add -p 8080:80 (source port:container port)
#docker run -dit -p 8080:80 -p8081:443 --name debian2 debian
1
2
3
docker container ps
# Show running containers
# -a shows all containers, including those deactivated
1
2
3
4
5
6
7
docker images
#Show all installed images

docker stop ID_STRING

docker start ID_STRING
# run a stopped container. It needs to have been 'run' before to be setup.
1
2
3
4
5
6
docker rm ID_STRING
# Remove a container (after it is stopped)

docker rm $(docker container ls -aq)
# The above remove all containers, the 'q' returns only the IDs
# Add a -f to force a container's removal, even if it is running
1
2
docker exec -it ID_STRING bash
# Run the container in interactive bash mode

New Docker bindings:
https://www.edureka.co/community/20973/how-do-i-assign-port-mapping-to-an-existing-docker-container

1
2
3
4
docker stop container_id
docker commit container_id container_id2
docker run -p 8080:8080 -dit container_id2
#docker run -v /var/run/docker.sock:/var/run/docker.sock -p 8080:8080 ID_STRING
1
2
docker login --username=mocomakers
#Login command line

 

1
2
3
4
docker commit -c "EXPOSE 8080" dev_container mocomakers/dev_container
docker tag mocomakers/dev_container mocomakers/dev_container
#docker tag my-image username/my-repo
docker push mocomakers/dev_container

 

1
2
docker run -p 8080:8080 -dit --name dev_container mocomakers/dev_container
# Recreate the container from the image

Leave a Reply

Your email address will not be published. Required fields are marked *