How to build and push a container image
This page explains how to create a simple Dockerfile to containerize your applications for deployment using Scaleway Serverless Containers.
Before you startLink to this anchor
To complete the actions presented below, you must have:
- A Scaleway account logged into the console
- Owner status or IAM permissions allowing you to perform actions in the intended Organization
- Installed Docker engine or the Docker daemon locally
- Created a Scaleway Registry namespace
- A valid API key
How to create a DockerfileLink to this anchor
-
In a new folder, create a file named
Dockerfile
. -
Add the following content to your Dockerfile, adjusting the base image and commands according to your application:
# Use the official Nginx imageFROM nginx:alpine# Create simple HTML content directly in the DockerfileRUN echo "<!DOCTYPE html><html><head><title>Demo</title></head><body><h1>Hello Scaleway Serverless Containers!</h1><p>Served by Nginx</p></body></html>" > /usr/share/nginx/html/index.html# For documentation purposesEXPOSE 8080# Modify Nginx configuration to listen on 8080RUN sed -i 's/listen\(.*\)80;/listen 8080;/' /etc/nginx/conf.d/default.conf# Start NginxCMD ["nginx", "-g", "daemon off;"]
# Use the official Node.js slim imageFROM node:22-slim# Create app directoryWORKDIR /usr/src/app# Create package.json and simple Express app directly in DockerfileRUN echo '{"name":"scaleway-serverless","version":"1.0.0","description":"","main":"server.js","scripts":{"start":"node server.js"},"dependencies":{"express":"^5"}}' > package.json && \npm install && \echo "const express = require('express');\nconst app = express();\nconst port = process.env.PORT || 8080;\n\napp.get('/', (req, res) => {\n res.send('<!DOCTYPE html><html><body><h1>Hello from Scaleway Serverless!</h1></body></html>');\n});\n\napp.listen(port, () => {\n console.log(`Server running on port \${port}`);\n});" > server.js# Start the applicationCMD ["npm", "start"]
# Use the official Python slim imageFROM python:3.13-slim# Install FlaskRUN pip install flask gunicorn# Create a simple Flask app directly in the DockerfileRUN echo "from flask import Flask\napp = Flask(__name__)\n\n@app.route('/')\ndef hello():\n return '<!DOCTYPE html><html><body><h1>Hello from Flask on Scaleway Serverless!</h1></body></html>'\n\nif __name__ == '__main__':\n app.run(host='0.0.0.0', port=8080)" > app.py# Run the app with GunicornCMD exec gunicorn --bind :$PORT --workers 1 --threads 8 app:app
How to build and push your image from your DockerfileLink to this anchor
-
Open a terminal and navigate to the directory containing your Dockerfile.
-
Run the following command to build your Docker image:
docker build -t my-application . -
Run the command below to log in to your Scaleway account in the terminal. Make sure that you replace the placeholder values with your own:
docker login rg.fr-par.scw.cloud/your-container-registry-namespace -u nologin --password-stdin <<< "$SCW_SECRET_KEY" -
Tag your Docker image so it matches your Scaleway registry’s format:
docker tag my-application:latest rg.fr-par.scw.cloud/your-container-registry-namespace/my-application:latest -
Push the Docker image to the Scaleway Container Registry:
docker push rg.fr-par.scw.cloud/your-container-registry-namespace/my-application:latest
You can now access your container image from the Scaleway Container Registry, and deploy a Serverless Container from this image.