Skip to content

Commit d1ed2e0

Browse files
committed
docs(SRV): update
1 parent c3b8817 commit d1ed2e0

File tree

1 file changed

+80
-20
lines changed

1 file changed

+80
-20
lines changed

pages/serverless-containers/how-to/build-push-container-image.mdx

Lines changed: 80 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
22
meta:
3-
title: How to create a Dockerfile
4-
description: Learn how to create a Dockerfile for deploying containerized applications.
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.
55
content:
6-
h1: How to create a Dockerfile
7-
paragraph: Learn how to create a Dockerfile to containerize your applications for deployment on Scaleway or any other containerized platform.
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.
88
tags: create dockerfile containerize application deployment scaleway
99
dates:
1010
validation: 2025-04-02
@@ -16,12 +16,72 @@ categories:
1616

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

19-
## How to Write a Dockerfile
19+
<Macro id="requirements" />
2020

21-
1. Create a file named `Dockerfile` in your project directory.
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`.
2230

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

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>
2585
```dockerfile
2686
# Use an official base image
2787
FROM python:3.9-slim
@@ -51,26 +111,26 @@ CMD ["python", "app.py"]
51111

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

54-
```bash
55-
docker build -t my-application .
56-
```
114+
```bash
115+
docker build -t my-application .
116+
```
57117

58-
3. Log in to your Scaleway account in the terminal:
118+
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:
59119

60-
```
61-
docker login -u <your-email> --password-stdin
62-
```
120+
```
121+
docker login rg.fr-par.scw.cloud/your-container-registry-namespace -u nologin --password-stdin <<< "$SCW_SECRET_KEY"
122+
```
63123

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

66-
```
67-
docker tag my-application
68-
```
126+
```
127+
docker tag my-application:latest rg.fr-par.scw.cloud/your-container-registry-namespace/my-application:latest
128+
```
69129

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

72-
```
73-
docker push
74-
```
132+
```
133+
docker push rg.fr-par.scw.cloud/your-container-registry-namespace/my-application:latest
134+
```
75135

76-
You can now access your container image from the [Scaleway Container Registry](https://console.scaleway.com/)
136+
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.

0 commit comments

Comments
 (0)