I can’t start image with clear installed Ubuntu. Then trying to install Nginx
and PHP
in Dockerfile
.
I use command docker-compose up -d
to to prepare and start container, but it always restarting.
Where is the error? Here is my code.
docker-compose.yml
:
version: '3'
services:
ubuntu:
build:
context: .
dockerfile: Dockerfile
ports:
- 80:80
volumes:
- ./data:/var/data
Dockerfile
:
FROM ubuntu:latest
RUN apt update -y && apt upgrade -y && apt autoremove -y
&& apt install nginx -y
&& apt install php -y
CMD ["bash"]
2
Answers
It’s using the latest Ubuntu image. I had a similar issue except it kept hanging.
Change the first line of your Dockerfile to:
FROM ubuntu:20.04
I have tried
docker pull ubuntu
thendocker run ubuntu
.docker ps
was empty. It means the container starts and ends quickly.I search
docker inspect ubuntu
and found"Cmd": "bash"
.Then I have tried
docker run -it ubuntu
and I had an access to the bash in the ubuntu container. But when I exited, the container closed.I think you should read and learn from the official nginx for example:
https://github.com/nginxinc/docker-nginx/blob/f958fbacada447737319e979db45a1da49123142/mainline/debian/Dockerfile
Your problem is your command: you should use something like
CMD ["nginx", "-g", "daemon off;"]
EDIT: I think you should use a Dockerfile for your nginx and another for your php. Then call your images in a docker-compose.yml