- 今天刚学习 docker-compose,我使用 docker-compose+Dockerfile。只创建了容器了,没有运行容器,直接退出了,不知道是什么原因。
- 下面是配置文件和启动命令
[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