Skip to content

Commit 82a595f

Browse files
SamyOubouaziznerda-codesRoRoJ
authored
docs(SRV): add build push image doc for cass & jobs MTA-5835 (#4767)
* docs(SRV): add build push image doc for cass & jobs MTA-5835 * docs(SRV): update * docs(SRV): update * docs(SRV): update * docs(SRV): update * docs(SRV): update * docs(SRV): update * Apply suggestions from code review Co-authored-by: Néda <[email protected]> Co-authored-by: Rowena Jones <[email protected]> --------- Co-authored-by: Néda <[email protected]> Co-authored-by: Rowena Jones <[email protected]>
1 parent e3a4985 commit 82a595f

File tree

3 files changed

+225
-0
lines changed

3 files changed

+225
-0
lines changed

menu/navigation.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3945,6 +3945,10 @@
39453945
"label": "Manage a container",
39463946
"slug": "manage-a-container"
39473947
},
3948+
{
3949+
"label": "Build and push a container image",
3950+
"slug": "build-push-container-image"
3951+
},
39483952
{
39493953
"label": "Add a custom domain to a container",
39503954
"slug": "add-a-custom-domain-to-a-container"
@@ -4097,6 +4101,10 @@
40974101
"label": "Monitor a job",
40984102
"slug": "monitor-job"
40994103
},
4104+
{
4105+
"label": "Build and push a container image",
4106+
"slug": "build-push-container-image"
4107+
},
41004108
{
41014109
"label": "Manage the scheduling of a job",
41024110
"slug": "manage-job-schedule"
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
---
2+
meta:
3+
title: How to build and push a container image
4+
description: How to build and push a container image based on a Dockerfile for deploying containerized applications with Scaleway Serverless Containers.
5+
content:
6+
h1: How to build and push a container image
7+
paragraph: How to build and push a container image based on a Dockerfile for deploying containerized applications with Scaleway Serverless Containers.
8+
tags: create dockerfile containerize application deployment scaleway
9+
dates:
10+
validation: 2025-04-02
11+
posted: 2021-04-02
12+
categories:
13+
- serverless
14+
- containers
15+
---
16+
17+
This page explains how to create a simple Dockerfile to containerize your applications for deployment using Scaleway Serverless Containers.
18+
19+
<Macro id="requirements" />
20+
21+
- A Scaleway account logged into the [console](https://console.scaleway.com)
22+
- [Owner](/iam/concepts/#owner) status or [IAM permissions](/iam/concepts/#permission) allowing you to perform actions in the intended Organization
23+
- Installed [Docker engine](https://docs.docker.com/engine/install/) or the Docker daemon locally
24+
- Created a [Scaleway Registry namespace](/container-registry/how-to/create-namespace/)
25+
- A valid [API key](/iam/how-to/create-api-keys/)
26+
27+
## How to create a Dockerfile
28+
29+
1. In a new folder, create a file named `Dockerfile`.
30+
31+
2. Add the following content to your Dockerfile, adjusting the base image and commands according to your application:
32+
33+
<Tabs id="dockerfile-examples">
34+
<TabsTab label="Nginx">
35+
```dockerfile
36+
# Use the official Nginx image
37+
FROM nginx:alpine
38+
39+
# Create simple HTML content directly in the Dockerfile
40+
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
41+
42+
# For documentation purposes
43+
EXPOSE 8080
44+
45+
# Modify Nginx configuration to listen on 8080
46+
RUN sed -i 's/listen\(.*\)80;/listen 8080;/' /etc/nginx/conf.d/default.conf
47+
48+
# Start Nginx
49+
CMD ["nginx", "-g", "daemon off;"]
50+
```
51+
</TabsTab>
52+
<TabsTab label="NodeJS">
53+
```dockerfile
54+
# Use the official Node.js slim image
55+
FROM node:22-slim
56+
57+
# Create app directory
58+
WORKDIR /usr/src/app
59+
60+
# Create package.json and simple Express app directly in Dockerfile
61+
RUN echo '{"name":"scaleway-serverless","version":"1.0.0","description":"","main":"server.js","scripts":{"start":"node server.js"},"dependencies":{"express":"^5"}}' > package.json && \
62+
npm install && \
63+
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
64+
65+
# Start the application
66+
CMD ["npm", "start"]
67+
```
68+
</TabsTab>
69+
<TabsTab label="Python Flask">
70+
```dockerfile
71+
# Use the official Python slim image
72+
FROM python:3.13-slim
73+
74+
# Install Flask
75+
RUN pip install flask gunicorn
76+
77+
# Create a simple Flask app directly in the Dockerfile
78+
RUN 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
79+
80+
# Run the app with Gunicorn
81+
CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 app:app
82+
```
83+
</TabsTab>
84+
</Tabs>
85+
86+
## How to build and push your image from your Dockerfile
87+
88+
1. Open a terminal and navigate to the directory containing your Dockerfile.
89+
90+
2. Run the following command to build your Docker image:
91+
92+
```bash
93+
docker build -t my-application .
94+
```
95+
96+
3. 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:
97+
98+
```
99+
docker login rg.fr-par.scw.cloud/your-container-registry-namespace -u nologin --password-stdin <<< "$SCW_SECRET_KEY"
100+
```
101+
102+
4. Tag your Docker image so it matches your Scaleway registry's format:
103+
104+
```
105+
docker tag my-application:latest rg.fr-par.scw.cloud/your-container-registry-namespace/my-application:latest
106+
```
107+
108+
5. Push the Docker image to the Scaleway Container Registry:
109+
110+
```
111+
docker push rg.fr-par.scw.cloud/your-container-registry-namespace/my-application:latest
112+
```
113+
114+
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.
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
---
2+
meta:
3+
title: How to build and push a container image
4+
description: How to build and push a container image based on a Dockerfile for deploying containerized applications with Scaleway Serverless Jobs.
5+
content:
6+
h1: How to build and push a container image
7+
paragraph: How to build and push a container image based on a Dockerfile for deploying containerized applications with Scaleway Serverless Jobs.
8+
tags: create dockerfile containerize application deployment scaleway
9+
dates:
10+
validation: 2025-04-02
11+
posted: 2021-04-01
12+
categories:
13+
- serverless
14+
- jobs
15+
---
16+
17+
This page explains how to create a simple Dockerfile to containerize your applications for deployment using Scaleway Serverless Jobs.
18+
19+
## How to Write a Dockerfile
20+
21+
1. Create a file named `Dockerfile` in your project directory.
22+
23+
2. Add the following content to your Dockerfile, adjusting the base image and commands according to your application:
24+
25+
<Tabs id="dockerfile-examples">
26+
<TabsTab label="Go">
27+
```dockerfile
28+
# Use the official Golang image to create a build artifact.
29+
FROM golang:1.24-alpine AS builder
30+
31+
# Create the main.go file with the Go source code
32+
RUN echo 'package main
33+
34+
import "fmt"
35+
36+
func main() {
37+
fmt.Println("Hello from Scaleway Serverless Jobs!")
38+
}' > main.go
39+
40+
# Build the Go app
41+
RUN go build -o main .
42+
43+
# Start a new stage from scratch
44+
FROM alpine:latest
45+
46+
# Copy the Pre-built binary file from the previous stage
47+
COPY --from=builder /app/main .
48+
49+
# Command to run the executable
50+
CMD ["./main"]
51+
```
52+
</TabsTab>
53+
<TabsTab label="Python">
54+
```dockerfile
55+
FROM python:3.13-slim
56+
57+
# Single-line Python script as entrypoint
58+
CMD ["python", "-c", "print('Hello from Scaleway Serverless Jobs!')"]
59+
```
60+
</TabsTab>
61+
<TabsTab label="Rust">
62+
```dockerfile
63+
FROM rust:1.86-slim
64+
65+
# Pre-compile a Rust binary during build
66+
RUN echo 'fn main() { println!("Hello from Scaleway Serverless Jobs!"); }' > main.rs && \
67+
rustc main.rs
68+
69+
# Run the pre-compiled binary
70+
CMD ["./main"]
71+
```
72+
</TabsTab>
73+
</Tabs>
74+
75+
## How to build and push your image from your Dockerfile
76+
77+
1. Open a terminal and navigate to the directory containing your Dockerfile.
78+
79+
2. Run the following command to build your Docker image:
80+
81+
```bash
82+
docker build -t my-application .
83+
```
84+
85+
3. 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.
86+
87+
```sh
88+
docker login rg.fr-par.scw.cloud/your-container-registry-namespace -u nologin --password-stdin <<< "$SCW_SECRET_KEY"
89+
```
90+
91+
4. Tag your Docker image so it matches your Scaleway registry's format:
92+
93+
```sh
94+
docker tag my-application:latest rg.fr-par.scw.cloud/your-container-registry-namespace/my-application:latest
95+
```
96+
97+
5. Push the Docker image to the Scaleway Container Registry:
98+
99+
```sh
100+
docker push rg.fr-par.scw.cloud/your-container-registry-namespace/my-application:latest
101+
```
102+
103+
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.

0 commit comments

Comments
 (0)