Last active
July 14, 2018 01:31
-
-
Save dexfs/7e8f0f3f3c7a012e7d47e794b0435606 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Docker Containers | |
Create an interactive terminal container with a name, an image, and a default command: | |
Usage: docker create -it --name=<name> <image> <command> | |
Example: docker create -it --name=foo ubuntu bash | |
List all running containers: | |
docker container ls | |
(list all containers, running or not): docker container ls -a | |
Start a docker container: | |
Usage: docker start <container name/id> | |
Example: docker start foo | |
Attach to a docker container: | |
Usage: docker attach <container name/id> | |
Example: docker attach foo | |
Remove a container: | |
Usage: docker rm <container name/id> | |
Example: docker rm foo | |
Force remove: docker rm foo -f | |
Run a new container: | |
Usage: docker run <image> <command> | |
Example with options: docker run --name=bar -it ubuntu bash | |
Remove all containers: | |
docker container ls -aq | xargs docker container rm | |
Execute a command in a running container: | |
Usage: docker exec <container name/id> <command> | |
Example (interactive, with tty): docker exec -it express bash | |
Docker Images | |
Remove a docker image: | |
Usage: docker image rmi <image id> | |
Example (only uses first 3 characters of image id): docker rmi 70b | |
Remove all images: | |
docker image ls -aq | xargs docker rmi -f | |
Search for a docker image on dockerhub: | |
Usage: docker search <image> | |
Example: docker search ubuntu | |
List docker images: | |
docker image ls | |
Build a Docker image: | |
Usage: docker build <path> | |
Example (also tags and names the build): docker build . -t org/serve:0.0.0 | |
Dockerfiles | |
Specify a base image: | |
Usage: FROM <base image> | |
Example: FROM node:latest | |
Set a working directory for the container: | |
Usage: WORKDIR <dir> | |
Example: WORKDIR /usr/src/app | |
Run a command for the container image: | |
Usage: RUN command | |
Command: RUN npm install -g serve | |
Copy files into the container: | |
Usage: COPY <local files/directories> <container files/directories> | |
Example: COPY ./display ./display | |
Inform that a port should be exposed | |
Usage: EXPOSE <port> | |
Example: EXPOSE 80 | |
Specify a default command for the container: | |
Usage (shell format): CMD <default command> | |
Example: CMD serve ./display | |
Usage (exec format, recommended): CMD [“default command”, “arguments”] | |
Example: CMD [“node”, “server.js”] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
docker container rm -f $(docker container ls -a | grep NAME | awk "{print \$1}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment