1

I am totally new on Docker and I want to set up a hello world project with Docker.

Currently, I'm using Apache on port 80 as a web server and I don't want to kill PID.

Here is my Dockerfile :

FROM php:7.2-cli
COPY src/ /usr/src/myapp
EXPOSE 80

after I run docker build -t hello-world ., simply run docker run -p 80:80 hello-world and found that the port in USED, so I changed the port to : docker run -p 8080:80 hello-world and I got Interactive shell.

so after research on google, I was able to run the server with this command :

docker container run --publish 8080:80 nginx 

Here is the question: How can I run the hello world app with 8080 port on my local computer?

fox
  • 181
  • 9

1 Answers1

1

How can I run the hello world app with 8080 port on my local computer?

That is what -p 8080:80 (as seen in container networking) does: Map TCP port 80 in the container to port 8080 on the Docker host.

That means on your local computer, http://127.0.0.1:8080 should display the NGiNX welcome message.

But depending on your docker setup, you might have some additional mapping to do (between the VM which hosts Docker, and Docker itself), as I explain in "Docker ports are not exposed".


I just want echo hello world in PHP, I tried [docker container run --publish 8080:80 hello-world] but i got this : Interactive shell

That is expected: your image is based on the php one, more precisely the 7.2-cli, whose main command is (using 7.2/stretch/cli/docker-php-entrypoint script):

docker-php-entrypoint php -a

You should use an image variant like a php:<version>-apache in order to see an application running, like in mfieldhouse/docker-php-helloworld With docker-php-entrypoint

FROM php:7.2-apache
COPY src/ /var/www/html
EXPOSE 80

With src including an index.php file:

<?php
echo "Hello, World from Docker! <br>";
echo "Hello ECS! <br>";
echo '<img src="https://www.docker.com/sites/default/files/horizontal.png">';
?>
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks for your answer, Yes currently I'm seeing the welcome message of nginx, but I don't know how to see my hello world message from http://127.0.0.1:8080 – fox Jan 06 '19 at 00:05
  • @Chino You mention the `php` image from which you are building your image in your question. That is not the same as `nginx`. Did you try a `docker container run` of your image with your `-p` option? – VonC Jan 06 '19 at 00:06
  • Yes, I just want echo hello world in PHP, I tried [docker container run --publish 8080:80 hello-world] but i got this : Interactive shell – fox Jan 06 '19 at 00:13
  • @Chino OK. I have edited my answer to show an actual php-based Docker-running hello-world application. – VonC Jan 06 '19 at 00:23
  • Ok, so I should build one more time and after that what should I run? should I run docker container run --publish 8080:80 hello-world? – fox Jan 06 '19 at 00:31
  • Thanks for your answer and your time, now it works with this : docker container run --publish 8080:80 hello-world – fox Jan 06 '19 at 00:33