Hosting a Containerized Web Server
This article details the successful deployment of a containerized static website using Docker Compose on App Server 1. The process involved creating a docker-compose.yml
file to define the service, handling a command not found
error for docker-compose
, and finally, launching the container.
Step 1: Creating the Docker Compose File
The first step was to define the container's configuration using a docker-compose.yml
file. This file specifies the image to use, the container's name, port mappings, and volume mounts.
The following content was created in the file located at /opt/docker/docker-compose.yml
:
version: '3'
services:
webserver:
image: httpd:latest
container_name: httpd
ports:
- "8082:80"
volumes:
- "/opt/finance:/usr/local/apache2/htdocs"
This configuration ensures:
- The
httpd:latest
image is used. - The container is named
httpd
. - Host port
8082
is mapped to the container's port80
. - The host directory
/opt/finance
is mounted as a volume to the container's/usr/local/apache2/htdocs
directory, which is the default location for web content.
Step 2: Troubleshooting Docker Compose Installation
An initial attempt to run the command resulted in the error sudo: docker-compose: command not found
. This indicated that the Docker Compose tool was not installed on the system. To resolve this, Docker Compose was installed by downloading the standalone binary and making it executable.
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
This process installed the latest version of Docker Compose to a system-wide location and gave it the necessary permissions to run.
Step 3: Deploying the Container
With Docker Compose now available, the next step was to run the command from the /opt/docker
directory to start the container in detached mode.
Command:
docker compose up -d
Output:
WARN[0000] /opt/docker/docker-compose.yml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion
[+] Running 7/7
✔ webserver Pulled 6.7s
... (layers pulled) ...
[+] Running 2/2
✔ Network docker_default Created 0.5s
✔ Container httpd Started 2.4s
The command successfully pulled the httpd
image, created a network, and started the container named httpd
. The warning about the version
attribute is informational and does not affect the container's operation.
The httpd
container is now running and serving the static website content from the /opt/finance
directory on port 8082
. This successfully completes the task of hosting the static content on a containerized platform as required by the application development team.
Top comments (0)