1.下载安装
sudo curl -L https://get.daocloud.io/docker/compose/releases/download/1.25.1/docker-compose-uname \ -s-uname -m -o /usr/local/bin/docker-compose
2.查看版本
sudo docker-compose version
3.赋运行权限
sudo chmod +x /usr/local/bin/docker-compose sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
4.启动
启动命令:docker-compose up -d # 查看正在运行的容器 docker-compose ps # 停止运行中的容器 docker-compose stop # 启动容器 docker-compose start # 重启容器 docker-compose restart # 删除已停止的容器 docker-compose rm # root用户权限进入容器 docker exec -it -u root container_id bash # 普通用户权限进入容器 docker exec -it container_id bash # 查看容器启动日志 docker logs -f container_id
5.如果启动失败,可能是权限不足
#修改文件夹权限 chmod -R 777 文件夹名称
6.将jar包打包成镜像
#指定文件参数-f docker build -t mydemo:1.0 -f ./DockerFile .
7.docker-compose.yml (nginx、mysql、redis)
version: '3' services: #nginx ngnix: container_name: nginx image: nginx:latest restart: always ports: - 80:80 privileged: true volumes: - /etc/docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf - /etc/docker/nginx/conf.d:/etc/nginx/conf.d - /etc/docker/nginx/logs:/var/log/nginx - /etc/docker/nginx/html:/usr/share/nginx/html - /etc/letsencrypt:/etc/letsencrypt - /etc/localtime:/etc/localtime #mysql mysql: container_name: mysql-8.0.25 image: mysql:8.0.25 #使用该参数,container内的root拥有真正的root权限,否则,container内的root只是外部的一个普通用户权限 #设置为true,不然数据卷可能挂载不了,启动不起 privileged: true restart: always ports: - "3306:3306" environment: MYSQL_ROOT_PASSWORD: root MYSQL_ROOT_USER: root MYSQL_PASS: root TZ: Asia/Shanghai command: --wait_timeout=31536000 --interactive_timeout=31536000 --max_connections=1000 --default-authentication-plugin=mysql_native_password volumes: #映射mysql的数据目录到宿主机,保存数据 - /etc/docker/mysql/data:/var/lib/mysql - /etc/docker/mysql/logs:/logs - /etc/docker/mysql/config/my.cnf:/etc/mysql/my.cnf - /etc/docker/mysql/mysql-files:/var/lib/mysql-files/ #redis redis: container_name: redis image: redis:latest restart: always command: redis-server /usr/local/redis/redis.conf ports: - 6379:6379 volumes: - /etc/docker/redis/data:/usr/local/redis/data - /etc/docker/redis/redis.conf:/usr/local/redis/redis.conf
8.Dockerfile的使用
#基础镜像源 FROM tomcat #启动后自动进入的路径 WORKDIR /usr/local/tomcat/webapps/ #创建文件夹 RUN mkdir ROOT #复制文件 COPY 1.jpg /usr/local/tomcat/webapps/ROOT/ #写入文件 RUN echo 'helloworld!!!!'>/usr/local/tomcat/webapps/ROOT/index.html 运行命令:docker build -t demo3 . -t:后面跟上镜像名字 空格加小数点:表示当前路径,即需要build的文件就在当前路径 注:当重复构建两个及以上相同镜像时 会出现虚悬镜像,这时候停掉容器,使用:docker image prune删除即可
未完待续。。
标签:Compose,nginx,redis,学习,etc,compose,mysql,Docker,docker From: https://www.cnblogs.com/walden-g/p/17105363.html