Install Apache webserver

Installing Apache webserver using Docker

Create the webserver documentroot in your homedir

1
$ mkdir website

Install Apache container

Now we pull the httpd:2.4 container from dockerhub and map the documentroot to our just created directory

1
$ sudo docker run -dit --name my-web -p 8080:80 -v ~/website/:/usr/local/apache2/htdocs/ httpd:2.4

We use docker ps to confirm our container is running

1
2
3
$ sudo docker ps
CONTAINER ID        IMAGE               COMMAND              CREATED             STATUS              PORTS                  NAMES
e837d58776cd        httpd:2.4           "httpd-foreground"   18 seconds ago      Up 16 seconds       0.0.0.0:8080->80/tcp   my-web

Create a simple homepage

Add index.html to our documentroot

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
cat <<EOF >>/website/index.html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>My website rocks!</title>
</head>
<body>
    <h1>Welcome to my homepage!</h1>
</body>
</html>
EOF

And we are done! To view the result simply open http://localhost:8080/ in your webbrowser!

Stop the container

1
$ sudo docker stop my-web

Remove the container

1
$ sudo docker rm my-web

Remove the dockerhub image

1
$ sudo docker image remove httpd:2.4

References

Last modified December 19, 2024: Update gaming.md (a1360a7)