Skip to content

Create a Container Image

This guide explains how to build and publish your own Docker container image using a simple website running on NGINX. The final result will be an image you can use on the Serverless Containers platform.


Prerequisites

  • Docker
    Install Docker on your machine: https://www.docker.com/

  • Online Repository
    Have access to a container registry such as Docker Hub.


Steps

Step 1: Write Your Application

Start by creating your application. In this example, it’s a basic HTML website.

Save the following content in a file named index.html inside a folder called My_Test_Website:

<!DOCTYPE html>
<html>
    <body>
        <h1>Docker test!</h1>
        <h1>It works on my machine...</h1>
        <p>Not sure if it'll work on yours?</p>
        <p>Try using containers!!</p>
    </body>
</html>
````

Your directory structure should look like this:
~/ServerlessContainers/ └── My_Test_Website/ └── index.html
---

### Step 2: Dockerize Your Application

Create a file named `Dockerfile` in the `~/ServerlessContainers` folder:

```Dockerfile
# Use the existing, official NGINX image as the base.
FROM nginx:latest

# Copy the website content into NGINX's default web directory.
COPY My_Test_Website /usr/share/nginx/html

This tells Docker to use NGINX and serve the contents of your website.


Step 3: Build the Docker Image

Open a terminal, navigate to the ~/ServerlessContainers directory, and run:

docker build -t serverlesscontainersdemo:1.0 .

To tag it for your container registry (e.g., Docker Hub), use your registry name:

docker build -t tilaa/serverlesscontainersdemo:1.0 .

This builds and tags your Docker image.


Step 4: Test Your Docker Container

Run your newly built container:

docker run -d -p 8080:80 serverlesscontainersdemo:1.0

This runs the container in the background and maps container port 80 to your local machine’s port 8080.

To check if it's running:

docker ps

Example output:

CONTAINER ID   IMAGE                          COMMAND                  CREATED          STATUS          PORTS
12abcd3e45fg   serverlesscontainersdemo:1.0   "/docker-entrypoint.…"   10 seconds ago   Up 10 seconds   0.0.0.0:8080->80/tcp

You can now open http://localhost:8080 in your browser and see your website.


Step 5: Upload to Your Container Registry

Login to Docker Hub:

docker login

Enter your username and personal access token (or password).

Push your image:

docker push tilaa/serverlesscontainersdemo:1.0

This uploads your image to your online container registry.


What's Next

You're ready to upload your image to the Serverless Containers platform.

For more information, check out the Docker documentation.