1. Container operations
- Run the container:
docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
Example:
docker run -it --rm ubuntu /bin/bash
- View running containers:
docker ps [OPTIONS]
Example:
docker ps -a
- Stop the container:
docker stop CONTAINER [CONTAINER...]
Example:
docker stop container_name
- Start a stopped container:
docker start CONTAINER [CONTAINER...]
Example:
docker start container_name
- Enter a running container:
docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
Example:
docker exec -it container_name /bin/bash
- Delete container:
docker rm CONTAINER [CONTAINER...]
Example:
docker rm container_name
- Copy files in Docker
Use the docker cp command to copy local files or directories to a running Docker container, or copy files or directories in a container to the local area.
Copy from local to container:
docker cp /path/to/local/file container_id:/path/in/container/
Copy from container to local:
docker cp container_id:/path/in/container/ /path/to/local/directory
2. Mirror operation
- Pull the image:
docker pull [OPTIONS] NAME[:TAG|@DIGEST]
Example:
docker pull ubuntu:latest
- View the local mirror list:
docker images [OPTIONS] [REPOSITORY[:TAG]]
Example:
docker images
- Delete local image:
docker rmi [OPTIONS] IMAGE [IMAGE...]
Example:
docker rmi image_name
3.Dockerfile operation
- Create Dockerfile:
Example:
FROM ubuntu:latest
RUN apt-get update && \
apt-get install -y python3 python3-pip && \
pip3 install flask
COPY ./app /app
WORKDIR /app
CMD python3 app.py
- Build image:
docker build [OPTIONS] PATH | URL | -
Example:
docker build -t myapp:latest .
The above are some common commands and operations of Docker. Docker has more functions and parameters. You can view detailed help documentation through `docker --help` or `docker COMMAND --help`.