关于 docker-compose 问题

2019-01-29 16:48:06 +08:00
 aaa5838769
[root@localhost compose]# cat docker-compose.yml 
version: '3'
services:
  web:
    build: .
    ports:
      - "8888:80"
[root@localhost compose]# cat Dockerfile 
FROM centos:7
MAINTAINER xy
RUN yum install -y httpd php php-gd php-mysql;systemctl enable httpd.service
RUN echo "<?php phpinfo()?>" > /var/www/html/index.php
EXPOSE 80

[root@localhost compose]# docker-compose up
 ---> d45344adbd48
Step 6/6 : EXPOSE 80
 ---> Running in 8ba263e41682
Removing intermediate container 8ba263e41682
 ---> b826f2af0a7c
Successfully built b826f2af0a7c
Successfully tagged compose_web:latest
WARNING: Image for service web was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
Creating compose_web_1 ... 
Creating compose_web_1 ... done
Attaching to compose_web_1
compose_web_1 exited with code 0

[root@localhost compose]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

[root@localhost compose]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS               NAMES
69675d705d29        compose_web         "/bin/bash"              14 seconds ago      Exited (0) 14 seconds ago                       compose_web_1
54794397b730        6d53ff0be550        "/bin/sh -c 'yum ins …"   2 hours ago         Exited (1) 2 hours ago    

[root@localhost compose]# docker-compose ps
    Name         Command    State    Ports 
------------------------------------------
compose_web_1   /bin/bash   Exit 0 
3822 次点击
所在节点    Docker
9 条回复
vissssa
2019-01-29 17:50:11 +08:00
docker-compose.yml 加个 command 就有显示了
keepeye
2019-01-29 18:06:33 +08:00
看 dockerfile 你没运行服务啊,CMD 呢?
keepeye
2019-01-29 18:08:40 +08:00
```
FROM ubuntu:14.04
MAINTAINER xxx
ADD bin/mtd /root/run
CMD ["/root/run"]
```
kaneg
2019-01-29 19:59:15 +08:00
docker 默认运行结束后就退出了,你需要一个不会结束的程序,比如 sleep infinity 或者 cat
aaa5838769
2019-01-30 09:38:41 +08:00
@keepeye 我的 Dockerfile,RUN 加了这么一句话 systemctl enable httpd.service
aaa5838769
2019-01-30 09:39:30 +08:00
@vissssa 好的,我一会试试,刚学习,很多知识点不知道
aaa5838769
2019-01-30 09:52:08 +08:00
@vissssa docker-compose.yml command 可以执行这句话不 systemctl start httpd,需要加别的参数来配合不?
keepeye
2019-01-30 10:08:57 +08:00
@aaa5838769 httpd 不要后台运行,docker 要求前台运行的程序,像 top,tail -f 等,否则 docker 命令跑完了直接就 exit 了
BlackHole1
2019-04-03 18:06:38 +08:00
最后加个 CMD bash

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/531641

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX