标签:database size stand running 因此 地址 跟踪 mit 参数
Compose是一个用于定义和运行多容器Docker应用程序的工具。使用Compose,您可以使用Compose文件来配置应用程序的服务。然后,使用单个命令,您可以从配置中创建并启动所有服务。
Compose非常适合开发,测试和登台环境以及CI工作流程。
(1)官方文档
(2)使用Compose基本上是一个三步过程
(3)
一个 docker-compose.yml 文件案例:
version: ‘2‘ services: web: build: . ports: - "5000:5000" volumes: - .:/code redis: image: redis
有关Compose文件的详细信息,请参阅 Compose文件参考。
(4)Compose具有管理应用程序整个生命周期的命令:
(1)前提
Docker Compose 依靠Docker Engine 进行任何有意义的工作,因此请确保您已在本地或远程安装Docker Engine,具体取决于您的设置。
要以非root用户身份运行Compose,请参阅以非root用户身份管理Docker。
(2)安装系统(主要讲linux、pip安装)
(1)下载安装
在gitlab https://github.com/docker/compose/releases 上查询适合自己的版本
我这里下载的是1.23.2 版本
sudo curl -L https://github.com/docker/compose/releases/download/1.23.2/docker-compose-Linux-x86_64 -o /usr/local/bin/docker-compose
(2)添加执行权限
$ chmod +x /usr/local/bin/docker-compose
(3)安装完成,查询版本
$ docker-compose --version docker-compose version 1.23.2, build 1110ad01
(1)使用pip安装
可以使用pypi安装Compose pip。如果你安装使用pip,我们建议你使用 virtualenv,因为许多操作系统都有python系统包与docker-compose依赖项冲突。请参阅virtualenv教程以开始使用。
pip install docker-compose
(2)安装为容器
Compose也可以在一个容器内运行,来自一个小的bash脚本包装器。要将compose安装为容器,请运行此命令。如果此示例已过期,请务必将版本号替换为所需的版本号:
$ sudo curl -L --fail https://github.com/docker/compose/releases/download/{{site.compose_version}}/run.sh -o /usr/local/bin/docker-compose $ sudo chmod +x /usr/local/bin/docker-compose
如果从Compose 1.2或更早版本升级,请在升级Compose后删除或迁移现有容器。这是因为,从版本1.3开始,Compose使用Docker标签来跟踪容器,并且需要重新创建容器以添加标签。
如果Compose检测到没有标签创建的容器,它将拒绝运行,因此您最终不会使用两组。如果要继续使用现有容器(例如,因为它们具有要保留的数据卷),可以使用Compose 1.5.x使用以下命令迁移它们:
docker-compose migrate-to-labels
或者,如果您不担心保留它们,可以将它们删除。撰写只是创建新的。
docker container rm -f -v myapp_web_1 myapp_db_1 ...
正常系统安装卸载:
sudo rm /usr/local/bin/docker-compose
pip安装卸载:
pip uninstall docker-compose
(1)创建compose 工作目录
[root@along ~]# mkdir composetest
[root@along ~]# cd composetest/
(2)创建一个app.py文件,后面在项目目录中调用文件
[root@along composetest]# vim app.py import time import redis from flask import Flask app = Flask(__name__) cache = redis.Redis(host=‘redis‘, port=6379) def get_hit_count(): retries = 5 while True: try: return cache.incr(‘hits‘) except redis.exceptions.ConnectionError as exc: if retries == 0: raise exc retries -= 1 time.sleep(0.5) @app.route(‘/‘) def hello(): count = get_hit_count() return ‘Hello World! I have been seen {} times.\n‘.format(count) if __name__ == "__main__": app.run(host="0.0.0.0", debug=True)
注:redis是应用程序网络上redis容器的主机名。我们使用Redis的默认端口6379。
(3)创建requirements.txt 项目目录中调用的另一个文件
[root@along composetest]# vim requirements.txt
flask
redis
创建一个名为的文件Dockerfile
[root@along composetest]# vim Dockerfile FROM python:3.4-alpine ADD . /code WORKDIR /code RUN pip install -r requirements.txt CMD ["python", "app.py"]
注:从Python 3.4映像开始构建映像。详细的dockerfile用法详见:Docker系列07—Dockerfile 详解
创建docker-compose.yml项目目录中调用的文件
[root@along composetest]# vim docker-compose.yml version: ‘3‘ services: web: build: . ports: - "5000:5000" redis: image: "redis:alpine"
此Compose文件定义了两个服务,web和redis。该web服务:
该redis服务使用从Docker Hub注册表中提取的公共 Redis映像。
(1)在项目目录中,启动应用程序 docker-compose up
[root@along composetest]# docker-compose up Recreating composetest_web_1 ... done Starting composetest_redis_1 ... done Attaching to composetest_redis_1, composetest_web_1 redis_1 | 1:C 15 Jan 2019 07:03:23.107 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo redis_1 | 1:C 15 Jan 2019 07:03:23.107 # Redis version=5.0.3, bits=64, commit=00000000, modified=0, pid=1, just started redis_1 | 1:C 15 Jan 2019 07:03:23.107 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf redis_1 | 1:M 15 Jan 2019 07:03:23.108 * Running mode=standalone, port=6379. redis_1 | 1:M 15 Jan 2019 07:03:23.108 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128. redis_1 | 1:M 15 Jan 2019 07:03:23.108 # Server initialized redis_1 | 1:M 15 Jan 2019 07:03:23.108 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add ‘vm.overcommit_memory = 1‘ to /etc/sysctl.conf and then reboot or run the command ‘sysctl vm.overcommit_memory=1‘ for this to take effect. redis_1 | 1:M 15 Jan 2019 07:03:23.108 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command ‘echo never > /sys/kernel/mm/transparent_hugepage/enabled‘ as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled. redis_1 | 1:M 15 Jan 2019 07:03:23.108 * DB loaded from disk: 0.000 seconds redis_1 | 1:M 15 Jan 2019 07:03:23.108 * Ready to accept connections
(2)浏览器查询http://192.168.130.102:5000/,验证
(3)刷新页面,数字应该增加
(4)另开一个终端,查看镜像验证
[root@along harbor]# docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE composetest_web latest ca6d50ca9694 About a minute ago 77.2MB redis alpine b42dc832c855 3 weeks ago 40.9MB python 3.4-alpine bb81744a76cf 3 weeks ago 65.8MB
(5)关闭服务
在新开的终端docker-compose down,或者在启动应用程序的原始终端中按CTRL + C来停止应用程序。
[root@along composetest]# vim docker-compose.yml version: ‘3‘ services: web: build: . ports: - "5000:5000" volumes: - .:/code redis: image: "redis:alpine"
注:新volumes密钥将主机上的项目目录(当前目录)/code安装到容器内,允许您动态修改代码,而无需重建映像。
(1)重新启动compose
[root@along composetest]# docker-compose up Recreating composetest_web_1 ... done Starting composetest_redis_1 ... done Attaching to composetest_redis_1, composetest_web_1 redis_1 | 1:C 15 Jan 2019 07:03:23.107 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo redis_1 | 1:C 15 Jan 2019 07:03:23.107 # Redis version=5.0.3, bits=64, commit=00000000, modified=0, pid=1, just started redis_1 | 1:C 15 Jan 2019 07:03:23.107 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf redis_1 | 1:M 15 Jan 2019 07:03:23.108 * Running mode=standalone, port=6379.
(2)在宿主机的存储卷上,修改代码
[root@along composetest]# vim app.py return ‘Hello World! I am along! I have been seen {} times.\n‘.format(count)
将Hello World! 邮件更改为Hello World! I am along!
(3)再在浏览器刷新,验证成功
(1)在后台运行服务,-d(用于“分离”模式)
[root@along composetest]# docker-compose up -d
Starting composetest_web_1 ... done
Starting composetest_redis_1 ... done
(2)使用docker-compose ps以查看当前正在运行的内容
[root@along composetest]# docker-compose ps Name Command State Ports ------------------------------------------------------------------------------------- composetest_redis_1 docker-entrypoint.sh redis ... Up 6379/tcp composetest_web_1 python app.py Up 0.0.0.0:5000->5000/tcp
(3)docker-compose run命令允许您为服务运行一次性命令。例如,要查看web服务可用的环境变量 :
[root@along composetest]# docker-compose run web env PATH=/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin HOSTNAME=3848578f8fff TERM=xterm LANG=C.UTF-8 GPG_KEY=97FC712E4C024BBEA48A61ED3A5CA953F73C700D PYTHON_VERSION=3.4.9 PYTHON_PIP_VERSION=18.1 HOME=/root
(4)停止服务
[root@along composetest]# docker-compose stop
Stopping composetest_web_1 ... done
Stopping composetest_redis_1 ... done
(5)使用该down 命令完全删除容器。加--volumes 参数还可以删除Redis容器使用的数据卷
[root@along composetest]# docker-compose down --volumes
Removing composetest_web_run_18e4bbaa4b33 ... done
Removing composetest_web_1 ... done
Removing composetest_redis_1 ... done
Removing network composetest_default
官网地址http://www.jumpserver.org
GitHub地址https://github.com/jumpserver/jumpserver
1. 搭建docker环境
2. 下载docker-compose
git clone https://github.com/wojiushixiaobai/docker-compose.git
3. 修改docker-compose.yaml,这步可以跳过,我是改成把数据挂载到自定义目录了,默认是挂载到数据卷
version: ‘3‘ services: mysql: image: mysql:5.7 container_name: jms_mysql restart: always tty: true environment: MYSQL_ROOT_PASSWORD: $MYSQL_ROOT_PASSWORD MYSQL_DATABASE: jumpserver command: --character-set-server=utf8 volumes: - /wdata/server/jumpserver/data/db-data:/var/lib/mysql networks: - jumpserver redis: image: redis:alpine container_name: jms_redis restart: always tty: true volumes: - /wdata/server/jumpserver/data/redis-data:/data networks: - jumpserver core: image: wojiushixiaobai/jms_core:${Version} container_name: jms_core hostname: jms_core restart: always tty: true environment: SECRET_KEY: $SECRET_KEY BOOTSTRAP_TOKEN: $BOOTSTRAP_TOKEN DB_ENGINE: mysql DB_HOST: mysql DB_PORT: 3306 DB_USER: root DB_PASSWORD: $MYSQL_ROOT_PASSWORD DB_NAME: jumpserver REDIS_HOST: redis depends_on: - mysql - redis volumes: - /wdata/server/jumpserver/data/static:/opt/jumpserver/data/static - /wdata/server/jumpserver/data/media:/opt/jumpserver/data/media - /wdata/server/jumpserver/data/logs:/opt/jumpserver/logs networks: - jumpserver koko: image: wojiushixiaobai/jms_koko:${Version} container_name: jms_koko restart: always tty: true environment: CORE_HOST: http://core:8080 BOOTSTRAP_TOKEN: $BOOTSTRAP_TOKEN depends_on: - core - mysql - redis volumes: - /wdata/server/jumpserver/data/keys-data:/opt/koko/data/keys ports: - 2222:2222 networks: - jumpserver guacamole: image: wojiushixiaobai/jms_guacamole:${Version} container_name: jms_guacamole restart: always tty: true environment: JUMPSERVER_SERVER: http://core:8080 BOOTSTRAP_TOKEN: $BOOTSTRAP_TOKEN JUMPSERVER_KEY_DIR: /config/guacamole/keys GUACAMOLE_HOME: /config/guacamole GUACAMOLE_LOG_LEVEL: ERROR JUMPSERVER_CLEAR_DRIVE_SESSION: ‘true‘ JUMPSERVER_ENABLE_DRIVE: ‘true‘ depends_on: - core - mysql - redis volumes: - /wdata/server/jumpserver/data/gua-key:/config/guacamole/keys networks: - jumpserver nginx: image: wojiushixiaobai/jms_nginx:${Version} container_name: jms_nginx restart: always tty: true depends_on: - core - koko - mysql - redis volumes: - /wdata/server/jumpserver/data/static:/opt/jumpserver/data/static - /wdata/server/jumpserver/data/media:/opt/jumpserver/data/media ports: - 80:80 networks: - jumpserver #volumes: # static: # media: # logs: # db-data: # redis-data: # keys-data: # gua-key: networks: jumpserver:
4. 启动容器并查看
docker-compose up -d
6. 访问
浏览器访问: http://<容器所在服务器IP>
SSH 访问: ssh -p 2222 <容器所在服务器IP>
XShell 等工具请添加 connection 连接, 默认 ssh 端口 2222
默认管理员账户 admin 密码 admin
标签:database size stand running 因此 地址 跟踪 mit 参数
原文地址:https://www.cnblogs.com/deny/p/12502937.html