Skip to content

Instantly share code, notes, and snippets.

@allysonsouza
Last active February 24, 2024 16:49
Show Gist options
  • Save allysonsouza/2b093693a255f989731095fd1ab50120 to your computer and use it in GitHub Desktop.
Save allysonsouza/2b093693a255f989731095fd1ab50120 to your computer and use it in GitHub Desktop.
[Docker Snippets] Docker snippets that can be useful on daily basis #docker

Docker Snippets

Build image

Uses the Dockerfile to build a new image.

docker build -t [IMAGE-NAME] .

  • -t flag tags your image
  • . at end tells build to search for Dockerfile on current dir

Run application

docker run -dp 127.0.0.1:3000:3000 [IMAGE-NAME]

  • -d flag (--detach) runs the container in background
  • -p flag (--publish) creates a port mapping host and container HOST:CONTAINER

List containers

docker ps

Stop all running containers

https://docs.docker.com/engine/reference/commandline/stop/

docker stop $(docker ps -q -a)

Stop specific container

https://docs.docker.com/engine/reference/commandline/rm/

docker container rm #{container_name}

Remove all containers

docker rm $(docker ps -q -a)

Remove all unused networks

https://docs.docker.com/engine/reference/commandline/network_prune/

docker network prune -f

Inspect volume

Return info about the given volume.

docker volume inspect [VOLUME-NAME]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment