[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
1
vissssa 2019-01-29 17:50:11 +08:00
docker-compose.yml 加个 command 就有显示了
|
2
keepeye 2019-01-29 18:06:33 +08:00
看 dockerfile 你没运行服务啊,CMD 呢?
|
3
keepeye 2019-01-29 18:08:40 +08:00
```
FROM ubuntu:14.04 MAINTAINER xxx ADD bin/mtd /root/run CMD ["/root/run"] ``` |
4
kaneg 2019-01-29 19:59:15 +08:00 via iPhone
docker 默认运行结束后就退出了,你需要一个不会结束的程序,比如 sleep infinity 或者 cat
|
5
aaa5838769 OP @keepeye 我的 Dockerfile,RUN 加了这么一句话 systemctl enable httpd.service
|
6
aaa5838769 OP @vissssa 好的,我一会试试,刚学习,很多知识点不知道
|
7
aaa5838769 OP @vissssa docker-compose.yml command 可以执行这句话不 systemctl start httpd,需要加别的参数来配合不?
|
8
keepeye 2019-01-30 10:08:57 +08:00
@aaa5838769 httpd 不要后台运行,docker 要求前台运行的程序,像 top,tail -f 等,否则 docker 命令跑完了直接就 exit 了
|
9
BlackHole1 2019-04-03 18:06:38 +08:00 via Android
最后加个 CMD bash
|