docker容器常用命令
docker run -it --rm image bash
docker run -itd --name c_name -p 10022:22 -v ./share:/home image:latest
docker run -d:后台运行容器,不保留交互能力。
docker run -it:前台运行容器,保留交互能力。
docker run -itd:后台运行容器,保留交互能力,允许在需要时连接到容器的终端
docker exec -it c_name bash
docker attach c_name
docker rm c_name
docker rm -f $(docker ps -aq)
docker commit c_name c_image:tag
docker commit -m="提交信息" -a="作者信息" c_name c_image:tag
docker top c_name
docker inspect c_name
docker cp c_name:/home/test.txt ./data
docker cp ./data c_name:/home
docker rename c_name c_name_new
docker镜像常用命令
docker search image
docker poll image
docker poll image:1.2.3
docker rmi image
docker rmi -f $(docker images -aq)
docker save image -o ./myimg.tar
docker load -i ./myimg.tar
Dockerfile
FROM python:3.8.10
ENV MY_PATH /usr/mytest
ARG BASE_IMAGE=ubuntu:20.04
WORKDIR /home
ADD ./share /home
COPY ./share /home
RUN apt-get update
RUN apt-get install -y openssh-server
RUN useradd -m user && echo 'user:123456' | chpasswd
USER user
VOLUME /home
EXPOSE 22
CMD echo "Hello, World!"
CMD ["echo", "Hello, World!"]
ENTRYPOINT echo "Hello, World!"
ENTRYPOINT ["echo", "Hello, World!"]
ENTRYPOINT ["echo"]
CMD ["Hello, World!"]
docker build -t myimage .
docker build --no-cache -t myimage .
docker build --build-arg BASE_IMAGE=alpine:3.12 -t myimage .
docker-compose.yml
version: "3.8"
services:
mysql:
image: mysql:8.0
container_name: ruoyi-mysql
restart: always
ports:
- 3306:3306
environment:
- MYSQL_ROOT_PASSWORD=123456
- MYSQL_DATABASE=ry-vue
- MYSQL_USER=ruoyi
- MYSQL_PASSWORD=123456
volumes:
- ./mysql/data:/var/lib/mysql
- ./mysql/sql:/docker-entrypoint-initdb.d
redis:
image: redis:7.2
container_name: ruoyi-redis
restart: always
ports:
- 6379:6379
volumes:
- ./redis/data:/data
backend:
image: openjdk:8u342
container_name: ruoyi-backend
restart: always
ports:
- 8080:8080
volumes:
- ./backend/ruoyi-admin.jar:/home/backend/ruoyi-admin.jar
environment:
- TZ=Asia/Shanghai
command: ["java", "-jar", "/home/backend/ruoyi-admin.jar"]
depends_on:
- redis
- mysql
frontend:
image: nginx:1.25
container_name: ruoyi-frontend
restart: always
ports:
- 8088:80
environment:
- TZ=Asia/Shanghai
volumes:
- ./nginx/dist:/home/nginx/dist
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
depends_on:
- backend
docker-compose up -d