参考動画
Management
terminal
docker info Display system information
docker version Display the system's version
docker login Log into a Docker registry
Container & Image
terminal
// List All Docker images
docker images
// List running container
docker pc
Running & Stopping
terminal
docker pull [imageName] Pull an image from a registry
docker run [imageName] Run containers
docker run -d [imageName] Detached mode
docker start [containerName] Start stopped containers
docker ps List running containers
docker ps -a List running and stopped containers
docker stop [containerName] Stop containers
docker kill [containerName] Kill containers
docker image inspect [imageName] Get image info
Running a container
terminal
docker run -p 8080:80 --name webserver nginx
docker ps
docker stop webserver
docker rm webserver
Attach Shell
terminal
docker run -it nginx bash
docker exec -it [containerName] bash
Cleaning up
terminal
docker rm [containerName] Removes stopped containers
docker rm $(docker ps -a -q) Removes all stopped containers
docker images List images
docker rmi [imageName] Deletes the image
docker system prune -a Removes all images not in use by any containers
Building
terminal
docker build -t [name:tag] . Builds an image using a Dockerfile located in the same folder
docker build -t [name:tag] -f [fileName] Builds an image using a Dockerfile located in a differnt folder
docker tag [imageName] [name:tag] Tag an existing image
Dockerfile - static HTML site
Dockerfile
FROM nginx:alpine
COPY . /usr/share/nginx/html
terminal
docker build -t webserver-image:v1 .
docker run -d -p 8080:80 webserver-image:v1
curl localhost:8080
Dockerfile - Node site
Dockerfile
FROM alpine Base image
RUN apk add -update nodejs nodejs-npm Install Node and NPM using the package manager
WORKDIR /src
COPY . /src Copy the files from the build context
RUN npm install Run a command
EXPOSE 8080 Add metadata
CMD ["node", "index.js"]
Volumes Cheat Sheet
terminal
docker create volume [volumeName] Creates a new volume
docker volume ls Lists the volumes
docker volume inspect [volumeName] Display the volume info
docker volume rm [volumeName] Deletes a volume
docker vokume prune Deletes all volumes not mounted
