Skip to content

Instantly share code, notes, and snippets.

@Kasahs
Created November 14, 2017 13:56
Show Gist options
  • Save Kasahs/23a4f29306e6d7a23cb5d1f38532f0ee to your computer and use it in GitHub Desktop.
Save Kasahs/23a4f29306e6d7a23cb5d1f38532f0ee to your computer and use it in GitHub Desktop.
some useful commands and comments on docker usage
# Docker useful commands:
# Build docker container with tag name using Docker (Dockerfile should be in current dir)
docker build -t <choose_image_name>
# Start container with required commands, (one’s specified in CMD tag in Dockerfile)
docker run <image_name>
# Start container with shell of choice
docker run -it o4s-transactions sh
# View all docker containers
docker ps -a
# Remove docker container by id
docker rm <container_id>
# Remove all exited containers
docker rm $(docker ps -a -q -f status=exited)
# List all available images
docker image ls
# Remove image
docker rmi <image_id>
# Get a shell session into a container
docker exec -it <containerId or name> bash
# Useful PM2 commands with docker
docker exec -it <container-id> pm2 monit # Monitoring CPU/Usage of each process
docker exec -it <container-id> pm2 list # Listing managed processes
docker exec -it <container-id> pm2 show # Get more information about a process
docker exec -it <container-id> pm2 reload all # 0sec downtime reload all applications
#docker volumes
docker volume create <volume-name> # create new volume
docker volume ls # show existing volumes
docker volume rm <volume-name> # remove volume
docker volume inspect <volume-name> # inspect a volume
# mounting a volume to a container
docker run -d \
-it \
--name <container-name> \
--mount source=<volume-name>,target=/path/on/container \
<image-name:version>
# inspect container
docker inspect <container-name> # you will find info about mounted volumes here
# using a bind mount (not flexible but might be needed)
docker run -d \
-it \
--name <container-name> \
--mount type=bind,source="/path/on/host",target=/path/on/container \
<image-name:version>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment