Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions menu/navigation.json
Original file line number Diff line number Diff line change
Expand Up @@ -3931,6 +3931,10 @@
"label": "Manage a container",
"slug": "manage-a-container"
},
{
"label": "Build and push a container image",
"slug": "build-push-container-image"
},
{
"label": "Add a custom domain to a container",
"slug": "add-a-custom-domain-to-a-container"
Expand Down Expand Up @@ -4083,6 +4087,10 @@
"label": "Monitor a job",
"slug": "monitor-job"
},
{
"label": "Build and push a container image",
"slug": "build-push-container-image"
},
{
"label": "Manage the scheduling of a job",
"slug": "manage-job-schedule"
Expand Down
114 changes: 114 additions & 0 deletions pages/serverless-containers/how-to/build-push-container-image.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
---
meta:
title: How to build and push a container image
description: How to build and push a container image based on a Dockerfile for deploying containerized applications with Scaleway Serverless Containers.
content:
h1: How to build and push a container image
paragraph: How to build and push a container image based on a Dockerfile for deploying containerized applications with Scaleway Serverless Containers.
tags: create dockerfile containerize application deployment scaleway
dates:
validation: 2025-04-02
posted: 2021-04-02
categories:
- serverless
- containers
---

This page explains how to create a simple Dockerfile to containerize your applications for deployment using Scaleway Serverless Containers.

<Macro id="requirements" />

- A Scaleway account logged into the [console](https://console.scaleway.com)
- [Owner](/iam/concepts/#owner) status or [IAM permissions](/iam/concepts/#permission) allowing you to perform actions in the intended Organization
- Installed [Docker engine](https://docs.docker.com/engine/install/) or the Docker daemon locally.
- Created a [Scaleway Registry namespace](/container-registry/how-to/create-namespace/)
- A valid [API key](/iam/how-to/create-api-keys/)

## How to create a Dockerfile

1. In a new folder, create a file named `Dockerfile`.

2. Add the following content to your Dockerfile, adjusting the base image and commands according to your application:

<Tabs id="dockerfile-examples">
<TabsTab label="Nginx">
```dockerfile
# Use the official Nginx image
FROM nginx:alpine

# Create simple HTML content directly in the Dockerfile
RUN 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 purposes
EXPOSE 8080

# Modify Nginx configuration to listen on 8080
RUN sed -i 's/listen\(.*\)80;/listen 8080;/' /etc/nginx/conf.d/default.conf

# Start Nginx
CMD ["nginx", "-g", "daemon off;"]
```
</TabsTab>
<TabsTab label="NodeJS">
```dockerfile
# Use the official Node.js slim image
FROM node:22-slim

# Create app directory
WORKDIR /usr/src/app

# Create package.json and simple Express app directly in Dockerfile
RUN 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 application
CMD ["npm", "start"]
```
</TabsTab>
<TabsTab label="Python Flask">
```dockerfile
# Use the official Python slim image
FROM python:3.13-slim

# Install Flask
RUN pip install flask gunicorn

# Create a simple Flask app directly in the Dockerfile
RUN echo "from flask import Flask\napp = Flask(__name__)\n\[email protected]('/')\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 Gunicorn
CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 app:app
```
</TabsTab>
</Tabs>

## How to build and push your image from your dockerfile

1. Open a terminal and navigate to the directory containing your Dockerfile.

2. Run the following command to build your Docker image:

```bash
docker build -t my-application .
```

3. Run the command below to log in to your Scaleway account in the terminal. Do not forget to replace the placeholder with your Container Registry namespace endpoint:

```
docker login rg.fr-par.scw.cloud/your-container-registry-namespace -u nologin --password-stdin <<< "$SCW_SECRET_KEY"
```

4. 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
```

5. 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](https://console.scaleway.com/registry/namespaces), and [deploy a Serverless Container](/serverless-containers/how-to/deploy-container/#deploy-from-an-external-container-registry) from this image.
103 changes: 103 additions & 0 deletions pages/serverless-jobs/how-to/build-push-container-image.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
---
meta:
title: ow to build and push a container image
description: How to build and push a container image based on a Dockerfile for deploying containerized applications with Scaleway Serverless Jobs.
content:
h1: ow to build and push a container image
paragraph: How to build and push a container image based on a Dockerfile for deploying containerized applications with Scaleway Serverless Jobs.
tags: create dockerfile containerize application deployment scaleway
dates:
validation: 2025-04-02
posted: 2021-04-01
categories:
- serverless
- jobs
---

This page explains how to create a simple Dockerfile to containerize your applications for deployment using Scaleway Serverless Jobs.

## How to Write a Dockerfile

1. Create a file named `Dockerfile` in your project directory.

2. Add the following content to your Dockerfile, adjusting the base image and commands according to your application:

<Tabs id="dockerfile-examples">
<TabsTab label="Go">
```dockerfile
# Use the official Golang image to create a build artifact.
FROM golang:1.24-alpine AS builder

# Create the main.go file with the Go source code
RUN echo 'package main

import "fmt"

func main() {
fmt.Println("Hello from Scaleway Serverless Jobs!")
}' > main.go

# Build the Go app
RUN go build -o main .

# Start a new stage from scratch
FROM alpine:latest

# Copy the Pre-built binary file from the previous stage
COPY --from=builder /app/main .

# Command to run the executable
CMD ["./main"]
```
</TabsTab>
<TabsTab label="Python">
```dockerfile
FROM python:3.13-slim

# Single-line Python script as entrypoint
CMD ["python", "-c", "print('Hello from Scaleway Serverless Jobs!')"]
```
</TabsTab>
<TabsTab label="Rust">
```dockerfile
FROM rust:1.86-slim

# Pre-compile a Rust binary during build
RUN echo 'fn main() { println!("Hello from Scaleway Serverless Jobs!"); }' > main.rs && \
rustc main.rs

# Run the pre-compiled binary
CMD ["./main"]
```
</TabsTab>
</Tabs>

## How to build and push your image from your dockerfile

1. Open a terminal and navigate to the directory containing your Dockerfile.

2. Run the following command to build your Docker image:

```bash
docker build -t my-application .
```

3. Run the command below to log in to your Scaleway account in the terminal. Do not forget to replace the placeholder with your Container Registry namespace endpoint:

```sh
docker login rg.fr-par.scw.cloud/your-container-registry-namespace -u nologin --password-stdin <<< "$SCW_SECRET_KEY"
```

4. Tag your Docker image so it matches your Scaleway registry's format:

```sh
docker tag my-application:latest rg.fr-par.scw.cloud/your-container-registry-namespace/my-application:latest
```

5. Push the Docker image to the Scaleway Container Registry:

```sh
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](https://console.scaleway.com/registry/namespaces), and [deploy a Serverless Job](/serverless-jobs/reference-content/deploy-job/) from this image.