Skip to content

Instantly share code, notes, and snippets.

@GuillaumeJasmin
Last active March 27, 2018 08:12
Show Gist options
  • Save GuillaumeJasmin/7210c4c868b4fd44fabb87d11c57dbd7 to your computer and use it in GitHub Desktop.
Save GuillaumeJasmin/7210c4c868b4fd44fabb87d11c57dbd7 to your computer and use it in GitHub Desktop.
List of common Docker commands

Build

docker build . -t <IMAGE_NAME>

OR

docker build . -t <IMAGE_NAME>:<VERSION>

If version is not specifed, latest is set.

Run

docker run -dt --name <CONTAINER_NAME> <IMAGE_NAME>:<VERSION>

Enter into interactive shell

docker exec -it <CONTAINER_NAME> /bin/bash

Note: use /bin/bash of /bin/sh, depend on the system

Mount volume

docker run -dt --name <CONTAINER_NAME> -v /volume/onto/host:/volume/into/container <IMAGE_NAME>

Bind port

docker run -dt --name <CONTAINER_NAME> -p <HOST_PORT>:<CONTAINER_PORT> <IMAGE_NAME>

remove none image

docker rmi $(docker images | grep "^<none>" | awk '{print $3}')

commit a container

docker commit <OLD_CONTAINER> <NEW_IMAGE>

tag a container

dokcer tag <IMAGE_NAME>:<VERSION> <REGISTRY_URL>/<NAMESPACE>/<IMAGE_NAME>:<VERSION>

example

dokcer tag nginx registry.server.com/mycompany/nginx

push a container to a registry

docker login -u <USER> -p <PASSWORD> <REGISTRY_URL>

example

docker login -u john -p 123456 registry.myserver.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment