Skip to content

Instantly share code, notes, and snippets.

@linhai86
Last active October 31, 2017 05:47
Show Gist options
  • Save linhai86/ad6aafc5006a220e815dfc945637f848 to your computer and use it in GitHub Desktop.
Save linhai86/ad6aafc5006a220e815dfc945637f848 to your computer and use it in GitHub Desktop.

Build

docker build -t username/repository:tag .

Ship

docker login my.registry.com:8000

docker tag <image> username/repository:tag

docker push username/repository:tag

docker pull username/repository:tag

docker run username/repository:tag

Manage

docker ps
docker ps -all

docker container ls                                # List all running containers
docker container ls -a             # List all containers, even those not running

docker container stop <hash>           # Gracefully stop the specified container
docker container kill <hash>         # Force shutdown of the specified container

docker rm <container>

docker container rm <hash>        # Remove specified container from this machine
docker container rm $(docker container ls -a -q)         # Remove all containers

docker images
docker rmi <image>

docker image ls -a                             # List all images on this machine

docker image rm <image id>            # Remove specified image from this machine
docker image rm $(docker image ls -a -q)   # Remove all images from this machine

Run

docker run --rm -it --name my_container -p 4000:80 -v ~/dev:/code username/repository:tag /bin/bash

Commands for Dockerfile

Command Purpose Example
FROM First non-comment instruction in Dockerfile FROM ubuntu
COPY Copies mulitple source files from the context to the file system of the container at the specified path COPY .bash_profile /home
ENV Sets the environment variable ENV HOSTNAME=test
RUN Executes a command RUN apt-get update
CMD Defaults for an executing container CMD ["/bin/echo", "hello world"]
EXPOSE Informs the network ports that the container will listen on EXPOSE 8093
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment