Our biggest-ever sale. 60% off AI & data skills
Buy Now
Berlatih dan lacak kemajuan Anda.
Lanjutkan dengan GoogleDengan melanjutkan, Anda menyetujui Ketentuan Penggunaan, Kebijakan Privasi dan bahwa data Anda disimpan di AS.
Simpan lembar contekan ini di ujung jari Anda
Unduh PDF
# Display Docker version with docker --version
docker --version
# Display Docker system info with docker info
docker info
# Get help on Docker with docker --help
docker --help
# Get help on Docker command usage with docker {command} --help
docker run --help
# Run a container with docker run {image}
docker run hello-world # Runs a test container to check your installation works
# Run a container then use it to run a command with docker run {image} {command}
docker run python python -c "print('Python in Docker')" # Run Python & print text
docker run rocker/r-base r -e "print(lm(dist~speed, cars))" # Run R & print a model
# Run a container interactively with docker run --interactive --tty
docker run --interactive --tty rocker/r-base # Run R interactively
# Run a container, and remove it once you've finished with docker run --rm
docker run --rm mysql # Run MySQL, then clean up
# Run an image in the background with docker run --detach
docker run --detach postgres
# Run an image, assigning a name, with docker --name {name} run
docker run --name red1 redis # Run redis, naming the container as red1
# Run an image as a user with docker run --user {username}
docker run --user doctordocker mongo
# List all running containers with docker ps
docker ps
# List all containers with docker ps --all
docker ps --all
# List all containers matching a conditions with docker ps --filter '{key}={value}'
docker ps --filter 'name=red1'
# Show container log output with docker logs --follow {container}
docker run --name bb busybox sh -c "$(echo date)" # Print current datetime
docker logs --follow bb # Print what bb container printed
# docker run is equivalent to docker create + docker start
# Create a container from an image with docker create {image}
# Start a container with docker start {container}
docker create --name py --interactive --tty python
docker start --interactive --attach py
# Same as docker run --name py --interactive --tty python
# Create a new image from a container with docker container commit {container}
docker container commit
# Stop a container with docker stop {container}
# Container has option to save state or ignore request
docker stop py
# Kill a container with docker kill {container}# Container process finished immediately
docker kill py
# Kill and remove a container with docker rm --force {container}
docker rm --force py
# Stop then start a container with docker restart {container}
docker restart py
# Delete stopped containers with docker container prune
docker container prune
# Create an image from a container with docker container commit {container_id} {image}
# Find the container ID with docker ps --all
docker container commit 123456789abc newimage
# Build an image with docker build {path}
docker build .
# Build a tagged image with docker build --tag {name:tag} {path}
docker build --tag myimage:2023-edition .
# Build an image without using the cache docker build -no-cache {path}
docker build --no-cache .
# List all local images with docker images
docker images
# Show Docker disk usage with docker system df
docker system df
# Show image creation steps from intermediate layers with docker history {image}
docker history alpine
# Save an image to a file with docker save --output {filename}
# Usually combined with a compression tool like gzip
docker save julia | gzip > julia.tar.gz
# Load an image from a file with docker load --input {filename}
docker load --input julia.tar.gz
# Delete an image with docker rmi {image}
docker rmi rocker/r-base
# Log in to Docker with docker login --username {username}
docker login --username doctordocker
# Pull an image from a registry with docker pull {image}
docker pull julia
# Pull a version of an image from a registry with docker pull {image}:{tag}
docker pull julia:1.8.5-bullseye
# Tag an image to a repo with docker tag {image} {user}/{repo}
docker tag python doctordocker/myrepo
# Push an image to a registry with docker push {repo_tag}
docker push doctordocker/myrepo
# Search for an image with docker search "{image-search-text}
"docker search "py"
# Derive image from another image with FROM{image}
FROM ubuntu:jammy-20230301
# Set a build and runtime environment variable with ENV {name}={value}
ENV TZ="America/New_York"
# Set a build-time variable with ARG {name}={default_value}
ARG VERBOSE=1
# Set the working directory with WORKDIR {path}
WORKDIR /home
# Switch to the user with USER {username}
USER doctordocker
# Copy a local file into the image with COPY {existing_path} {image_path}
COPY ./settings/config.yml ./settings/config.yml
# Run a shell command during the build step with RUN {command}
# \ lets commands continue across multiple lines
# && means run this command only if the preceding command succeeded
RUN apt-get update \
&& install -y libxml2-dev
# Run a shell command on launch with CMD ["{executable}", "{param1}"]
# Each Dockerfile should only have 1 CMD statement
CMD ["python", "-i"] # Start Python interactively
Learn more about Docker certification in our separate guide!
blogs

blogs

cheat sheets