首页 > 其他分享 >Docker: docker-compose file

Docker: docker-compose file

时间:2023-09-25 11:46:52浏览次数:41  
标签:compose aaa 0.0 app nginx Docker docker

docker-compose.yaml:

version: '3.3'

services:
  nginx:
    image: nginx:latest
    ports:
      - 8080:80

With regards to the preceding docker-compose file, we have the term services that refers to all the applications that we would be running in one go. In this first example test, we can attempt to run the nginx container image under the service called nginx.
We can also set it such that we would export port 80 of the nginx container to our current workstation’s port 8080.

zzh@ZZHPC:/zdata/MyPrograms/Go/aaa$ docker compose -f docker-compose.yaml up
[+] Running 2/1
 ✔ Network aaa_default    Created                                                                                                                                 0.1s 
 ✔ Container aaa-nginx-1  Created                                                                                                                                 0.0s 
Attaching to aaa-nginx-1
aaa-nginx-1  | /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
aaa-nginx-1  | /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
aaa-nginx-1  | /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
aaa-nginx-1  | 10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
aaa-nginx-1  | 10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
aaa-nginx-1  | /docker-entrypoint.sh: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh
aaa-nginx-1  | /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
aaa-nginx-1  | /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
aaa-nginx-1  | /docker-entrypoint.sh: Configuration complete; ready for start up
aaa-nginx-1  | 2023/09/25 03:15:50 [notice] 1#1: using the "epoll" event method
aaa-nginx-1  | 2023/09/25 03:15:50 [notice] 1#1: nginx/1.25.2
aaa-nginx-1  | 2023/09/25 03:15:50 [notice] 1#1: built by gcc 12.2.0 (Debian 12.2.0-14) 
aaa-nginx-1  | 2023/09/25 03:15:50 [notice] 1#1: OS: Linux 6.2.0-33-generic
aaa-nginx-1  | 2023/09/25 03:15:50 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
aaa-nginx-1  | 2023/09/25 03:15:50 [notice] 1#1: start worker processes
aaa-nginx-1  | 2023/09/25 03:15:50 [notice] 1#1: start worker process 29
aaa-nginx-1  | 2023/09/25 03:15:50 [notice] 1#1: start worker process 30
aaa-nginx-1  | 2023/09/25 03:15:50 [notice] 1#1: start worker process 31
aaa-nginx-1  | 2023/09/25 03:15:50 [notice] 1#1: start worker process 32
aaa-nginx-1  | 2023/09/25 03:15:50 [notice] 1#1: start worker process 33
aaa-nginx-1  | 2023/09/25 03:15:50 [notice] 1#1: start worker process 34
^CGracefully stopping... (press Ctrl+C again to force)
Aborting on container exit...
[+] Stopping 1/1
 ✔ Container aaa-nginx-1  Stopped                                                                                                                                 0.4s 
canceled

We can stop running the nginx application via docker-compose by doing a keyboard interrupt. However, the application would still be around (although stopped), and we will probably be unable to rerun the command: docker-compose -f docker-compose.yaml up once more without any issue. To properly clean up, we can run the following command:

zzh@ZZHPC:/zdata/MyPrograms/Go/aaa$ docker compose -f docker-compose.yaml down
[+] Running 2/2
 ✔ Container aaa-nginx-1  Removed                                                                                                                                 0.0s 
 ✔ Network aaa_default    Removed

 

docker-compose.yaml:

version: '3.3'

services:
  app:
    build:
      context: .
      dockerfile: dockerfile
    ports:
      - 8080:8080

When we use build here, it serves as some sort of indication to docker-compose that the image for this service might require us to run a Docker container build process to generate it.

zzh@ZZHPC:/zdata/MyPrograms/Go/aaa$ docker compose -f docker-compose.yaml up -d
[+] Building 9.2s (12/12) FINISHED                                                                                                                      docker:default
 => [app internal] load .dockerignore                                                                                                                             0.0s
 => => transferring context: 2B                                                                                                                                   0.0s
 => [app internal] load build definition from Dockerfile                                                                                                          0.0s
 => => transferring dockerfile: 214B                                                                                                                              0.0s
 => [app internal] load metadata for docker.io/library/golang:1.21                                                                                                2.8s
 => [app 1/7] FROM docker.io/library/golang:1.21@sha256:c416ceeec1cdf037b80baef1ccb402c230ab83a9134b34c0902c542eb4539c82                                          0.0s
 => [app internal] load build context                                                                                                                             0.0s
 => => transferring context: 459B                                                                                                                                 0.0s
 => CACHED [app 2/7] WORKDIR /app                                                                                                                                 0.0s
 => CACHED [app 3/7] ADD go.mod go.sum ./                                                                                                                         0.0s
 => CACHED [app 4/7] RUN go env -w GOPROXY=https://goproxy.io,direct                                                                                              0.0s
 => CACHED [app 5/7] RUN go mod download                                                                                                                          0.0s
 => [app 6/7] ADD . .                                                                                                                                             0.0s
 => [app 7/7] RUN go build -o app .                                                                                                                               6.1s
 => [app] exporting to image                                                                                                                                      0.3s
 => => exporting layers                                                                                                                                           0.3s
 => => writing image sha256:c5ca78c1b68074e5e4031f248a133252105b44ba94a62d45497a9a7fe7348b1d                                                                      0.0s
 => => naming to docker.io/library/aaa-app                                                                                                                        0.0s
[+] Running 2/2
 ✔ Network aaa_default  Created                                                                                                                                   0.1s 
 ✔ Container aaa-app-1  Started

 

zzh@ZZHPC:/zdata/MyPrograms/Go/aaa$ docker compose logs
aaa-app-1  | 2023/09/25 03:28:10 Hello world sample started.

 

标签:compose,aaa,0.0,app,nginx,Docker,docker
From: https://www.cnblogs.com/zhangzhihui/p/17727602.html

相关文章

  • docker部署开发环境
    version:'3'services:mysql:image:mysql:5.6container_name:mysqlhostname:mysqlrestart:alwaysports:-3306:3306networks:-devvolumes:-./mysql/conf:/etc/mysql/conf.d-./mysql/da......
  • 服务器Docker搭建CUDA10.2+PaddleDetection2.4.2-GPU环境
    1、容器建立由于目标服务器的显卡版本较老,CUDA只支持到10.2,所以需要选用老版本Docker镜像,百度网盘链接:https://pan.baidu.com/s/1GiQzWRypaeBNFWETWFAV-Q?pwd=5f12 使用命令将镜像启动为容器:dockerrun--namenvidia-cuda10.2-cudnn7-1-p9001:22-p9002:8002-v/work/nod......
  • 使用 Docker Compose 安装 APISIX
    1.基本概念APISIX是Apache下的一款云原生的API网关,支持全生命周期的API管理,在应用中可以作为所有API调用的统一入口。APISIX有一些基础概念如下:Upstream,或者叫做上游,是一组目标主机的抽象,上游一组节点提供实际的业务服务,一般需要指定负载均衡策略去调用。Route,路由......
  • Docker容器数据卷(命令的方式)
    Docker容器数据卷(持久化数据+数据共享)具体操作:1-创建连接:1-dockerimages//查看镜像名字2-(小提示:pwd可以查看绝对路径)公式:dockerrun-it-v宿主机绝对目录(文件):容器内绝对目录(文件)[镜像名字]公式2:dockerrun-it-v宿主机绝对目录(文件):容器内绝......
  • docker
      一般在输入dockerps+镜像名/容器名 一、1、docker具体安装步骤 在虚拟机中安装https://blog.csdn.net/PyongSen/article/details/123053374其中在网站中安装不了docker,那就使用yum-yinstalldocker安装2、配置阿里云镜像加速sudomkdir-p/etc/dockers......
  • Docker Compose 容器编排
    docker-compose是docker官方的开源项目,负责实现对docker容器集群的快速编排简单的理解就是对多个容器进行快速的管理,如一键启动、一键stop等等……dockercompose官网下载安装老版本的需要去官网下载安装,新版本的直接使用yum进行安装即可[root@localhost~]#yum-yinstalldocke......
  • Docker - Optimized Dockerfile
    WehavetheincentivetooptimizeourDockerfileto buildsmallerimages.Someofthepointsthatwecanprobablycomeupwithwould bethefollowing:• NotusingGolangforourbaseimage.Golangisastaticallycompiled language—oncewehavethecompil......
  • Docker - ERROR: failed to solve: golang:latest: error getting credentials - err:
    Dockerfile:FROMgolang:latestWORKDIR/appADD..RUNgoenv-wGOPROXY=https://goproxy.io,directRUNgogetRUNgobuild-oapp.CMD["/app/app"] zzh@ZZHPC:/zdata/MyPrograms/Go/aaa$dockerbuild-ttest:v1.[+]Building1.3s(3/3)FINI......
  • Docker 部署 Elasticsearch 8.6.2
    Docker部署Elasticsearch8.6.2dockerpullelasticsearch:8.6.2mkdir-pv/home/zonglin/elasticsearch/pluginssudodockerrun--nameelasticsearch-p9200:9200-p9300:9300\--restart=always\-e"discovery.type=single-node"\-eES_JAVA_......
  • docker-compose 部署 phpmyadmin
    docker-compose.yamlversion:'3.9'services:phpmyadmin:image:phpmyadmincontainer_name:phpmyadminrestart:alwaysprivileged:trueenvironment:-PMA_HOST=192.168.0.152ports:-"8081:80"ne......