Reproducible Builds with Web Servers
Docker built successfully from dockerfile in 20 seconds.
There was a suggested improvement in the dockerfile to add JSON syntax.
WARN: JSONArgsRecommended: JSON arguments recommended for CMD to prevent unintended behavior related to OS signals
Web server config file
There is a COPY command in the dockerfile used to build the image. The custom nginx.conf file is in the same dir as dockerfile, and is copied to the default location for config files, in the linux dir /etc.
COPY nginx.conf /etc/nginx/nginx.conf
Convenient because config file and installation instructions to recreate an environment can be kept at one location in the file system.
There is a bash script that launches the containers, this is where the scalability first presents itself.
#!/bin/bash
# Create a string, add an incremental character subsequently in the for loop to create unique ports.
BASE_PORT=8000
# This for loop defines the number of containers. It launches them sequentially.
for i in {1..50}; do
CONTAINER_NAME=”nginx-python-$i”
PYTHON_PORT=$((BASE_PORT + i)) # Each container gets a unique port
echo “Launching container $CONTAINER_NAME with Python server on port $PYTHON_PORT”
# Run the container
docker run -d — name $CONTAINER_NAME -p $((8080 + i)):80 -e PYTHON_PORT=$PYTHON_PORT IMAGE_NAME
done
To parallelize, add character ‘&’
# Run the container in the background
docker run -d — name $CONTAINER_NAME -p $((8080 + i)):80 -e PYTHON_PORT=$PYTHON_PORT IMAGE_NAME &
done
# Wait for all background processes to finish
wait
echo “All containers launched in parallel!”
OR use GNU parallel.
Modify the bash script:
- create a function to launch_container()
- export the function to GNU parallel
launch_container() {
i=$1
CONTAINER_NAME=”nginx-python-$i”
PYTHON_PORT=$((BASE_PORT + i)) # Each container gets a unique port
echo “Launching container $CONTAINER_NAME with Python server on port $PYTHON_PORT”
docker run -d — name $CONTAINER_NAME -p $((8080 + i)):80 -e PYTHON_PORT=$PYTHON_PORT my-nginx-python
}
export -f launch_container
parallel launch_container ::: {1..50}
When the containers are running, output from $ docker ps:

Halted running 48 of the containers using this command:
docker ps -q | head -n 48 | xargs docker stop
docker ps → shows only 2 containers.
The ‘docker stop’ above chooses 48 containers at random or based on some order; to user-define or admin-define which 48, need a for-loop, which can be run using a bash script.
The mapping of ports:

Checking on the status of containers, ‘Status’ column can have value: created, up , and exited, in some cases with information on the time length since status changed.
