I'm trying to run Ubuntu in the docker container. I use Dockerfile with contents:

 FROM ubuntu:latest 

Or docker-compose.yml with the contents:

 version: '3' services: ubuntu: image: ubuntu:18.04 ports: - 32769:80 volumes: - /var/www:/var/www 

I do at a minimum, I want to run and see that everything works. Try to enter the container itself.

But the problem is that the container does not start and lies in the list of stopped

 $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES $ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ea3715e0c4f7 docker-compose-ubuntu-latest_ubuntu "/bin/sh -c /bin/bash" 4 minutes ago Exited (0) 4 minutes ago docker-compose-ubuntu-latest_ubuntu_1 

Tell me, please, what could be the problem? Just starting to study the docker, maybe doing something wrong.

Thank.

PS I tried to change the Dockerfile as follows:

 FROM ubuntu RUN apt-get update RUN apt-get install apache2 -y RUN service apache2 start CMD /bin/bash 

but the container still does not start. I can not even understand what could be the problem. No errors, just does not start.

Through docker-compose, it turns out to launch a bunch of several ready-made images, but it’s impossible to launch something adequate.

  • one
    if leaky abstractions take place (in the form of pre-files, composes, etc. add-ons), try without them . - aleksandr barakin
  • @ alexander-barakin Thank you, helped launch with -it See more about these keys and will experiment further - Cuthbert_Allgood
  • one
    docker-compose is not a holey abstraction, but a very smart and convenient wrapper for managing the application. If you read and use examples from the official documentation, everything will work and become very understandable after a while. Options in Docker is a key component . Examine them. Start with Docker, then Docker Compose. - diproart

1 answer 1

I recommend to look at this question in stackoverflow.

In short, in the first case (before PS) apache does not start for two reasons: (1) by default it is absent in the ubuntu image (2) there is no apache launch command. In the second case (after PS), the problem of the absence of apache is resolved and it remains only to register the correct command in the CMD of your docerfile, for example:

 CMD apachectl -D FOREGROUND 

And now the full answer.

In order for us to launch Apache in Docker, you need to create a Dockerfile file of the following content (copied from the link I indicated):

 FROM ubuntu # File Author / Maintainer MAINTAINER rmuktader # Update the repository sources list RUN apt-get update # Install and run apache RUN apt-get install -y apache2 && apt-get clean #ENTRYPOINT ["/usr/sbin/apache2", "-k", "start"] #ENV APACHE_RUN_USER www-data #ENV APACHE_RUN_GROUP www-data #ENV APACHE_LOG_DIR /var/log/apache2 EXPOSE 80 CMD apachectl -D FOREGROUND 

Next, from the directory in which the Dockerfile is located, start the image assembly

 docker build -t apache . 

As a result, an apache:latest image will be created, from which you can start the container with the command

 docker run -it -p 8080:80 apache 

And if everything is good, then you can go to the browser at localhost:8080 and watch the start page of the Apache.

For compose, the docker-compose.yml will look something like this:

 version: '3' services: apache: image: apache:latest ports: - 32769:80 volumes: - /var/www:/var/www 

Naturally, you need to make sure that in the /var/www directory of your host machine there is something “readable” for Apache.

Run:

 docker-compose up 

In the browser, go to the address localhost:32769 and observe the contents of the host machine's /var/www directory