# Create and start an HTTP server

In 
Published 2022-12-03

This tutorial explains to you how to create and start an HTTP server using Docker Compose.

When we are working with Docker Compose the main activity is to create the Docker Compose configuration file. In my case this is docker-compose.yaml.

Here is the content of docker-compose.yaml file:

docker-compose.yaml
version: '4.15'
services:
  apache:
    image: httpd:latest
    container_name: my-apache
    ports:
    - '8080:80'
    volumes:
    - ./my-website:/usr/local/apache2/htdocs

This will download and install the latest image of the Apache HTTP server. The container will have the my-apache name. Inside, into the container the HTTP server is running on the port 80. However, a mapping between host port 8080 and container port 80 is created.

When the docker-compose up is run, the local image is created and the container is started.

In my case the my-website folder has only one file (index.html) with the following content:

index.html
<html>
 <head>
    <title>This is a page from container</title>
 </head>
 <body>
    <p>Hello World !</p>

    <p>This message is from my server&nbsp; &#127801; !</p>
 </body>
</html>

Now when I ask for http://localhost:8080 resource in the browser I receive the page I have created for my site:

Also, on the Docker Desktop I can see the container in a running state: