From dff50fe16c1bd61cccc9f5ffd4ee10273169aab9 Mon Sep 17 00:00:00 2001 From: SamyOubouaziz Date: Wed, 2 Apr 2025 11:30:36 +0200 Subject: [PATCH 1/8] docs(SRV): add build push image doc for cass & jobs MTA-5835 --- menu/navigation.json | 8 ++ .../how-to/build-push-container-image.mdx | 76 +++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 pages/serverless-containers/how-to/build-push-container-image.mdx diff --git a/menu/navigation.json b/menu/navigation.json index 60cb6051ad..ecd3be46ae 100644 --- a/menu/navigation.json +++ b/menu/navigation.json @@ -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" @@ -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" diff --git a/pages/serverless-containers/how-to/build-push-container-image.mdx b/pages/serverless-containers/how-to/build-push-container-image.mdx new file mode 100644 index 0000000000..ec28a7c7de --- /dev/null +++ b/pages/serverless-containers/how-to/build-push-container-image.mdx @@ -0,0 +1,76 @@ +--- +meta: + title: How to create a Dockerfile + description: Learn how to create a Dockerfile for deploying containerized applications. +content: + h1: How to create a Dockerfile + paragraph: Learn how to create a Dockerfile to containerize your applications for deployment on Scaleway or any other containerized platform. +tags: create dockerfile containerize application deployment scaleway +dates: + validation: 2025-02-25 + posted: 2021-05-26 +categories: + - serverless + - containers +--- + +This page explains how to create a simple Dockerfile to containerize your applications for deployment using Scaleway Serverless Containers. + +## 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: + +```dockerfile +# Use an official base image +FROM python:3.9-slim + +# Set the working directory in the container +WORKDIR /app + +# Copy the current directory contents into the container at /app +COPY . /app + +# Install any needed packages specified in requirements.txt +RUN pip install --no-cache-dir -r requirements.txt + +# Make port 80 available to the world outside this container +EXPOSE 80 + +# Define environment variable +ENV NAME World + +# Run app.py when the container launches +CMD ["python", "app.py"] +``` + +## 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. Log in to your Scaleway account in the terminal: + +``` +docker login -u --password-stdin +``` + +4. Tag your Docker image so it matches your Scaleway registry's format: + +``` +docker tag my-application +``` + +5. Push the Docker image to the Scaleway Container Registry: + +``` +docker push +``` + +You can now access your container image from the [Scaleway Container Registry](https://console.scaleway.com/) \ No newline at end of file From c3b88179fb4c8bd067df6d29fdb8399c3f01b105 Mon Sep 17 00:00:00 2001 From: SamyOubouaziz Date: Wed, 2 Apr 2025 11:33:28 +0200 Subject: [PATCH 2/8] docs(SRV): update --- .../how-to/build-push-container-image.mdx | 4 +- .../how-to/build-push-container-image.mdx | 76 +++++++++++++++++++ 2 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 pages/serverless-jobs/how-to/build-push-container-image.mdx diff --git a/pages/serverless-containers/how-to/build-push-container-image.mdx b/pages/serverless-containers/how-to/build-push-container-image.mdx index ec28a7c7de..2519b45e0d 100644 --- a/pages/serverless-containers/how-to/build-push-container-image.mdx +++ b/pages/serverless-containers/how-to/build-push-container-image.mdx @@ -7,8 +7,8 @@ content: paragraph: Learn how to create a Dockerfile to containerize your applications for deployment on Scaleway or any other containerized platform. tags: create dockerfile containerize application deployment scaleway dates: - validation: 2025-02-25 - posted: 2021-05-26 + validation: 2025-04-02 + posted: 2021-04-02 categories: - serverless - containers diff --git a/pages/serverless-jobs/how-to/build-push-container-image.mdx b/pages/serverless-jobs/how-to/build-push-container-image.mdx new file mode 100644 index 0000000000..d620927e01 --- /dev/null +++ b/pages/serverless-jobs/how-to/build-push-container-image.mdx @@ -0,0 +1,76 @@ +--- +meta: + title: How to create a Dockerfile + description: Learn how to create a Dockerfile for deploying containerized applications. +content: + h1: How to create a Dockerfile + paragraph: Learn how to create a Dockerfile to containerize your applications for deployment on Scaleway or any other containerized platform. +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: + +```dockerfile +# Use an official base image +FROM python:3.9-slim + +# Set the working directory in the container +WORKDIR /app + +# Copy the current directory contents into the container at /app +COPY . /app + +# Install any needed packages specified in requirements.txt +RUN pip install --no-cache-dir -r requirements.txt + +# Make port 80 available to the world outside this container +EXPOSE 80 + +# Define environment variable +ENV NAME World + +# Run app.py when the container launches +CMD ["python", "app.py"] +``` + +## 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. Log in to your Scaleway account in the terminal: + +``` +docker login -u --password-stdin +``` + +4. Tag your Docker image so it matches your Scaleway registry's format: + +``` +docker tag my-application +``` + +5. Push the Docker image to the Scaleway Container Registry: + +``` +docker push +``` + +You can now access your container image from the [Scaleway Container Registry](https://console.scaleway.com/) \ No newline at end of file From d1ed2e05e3d86b56c3dd526d2231956133d4c135 Mon Sep 17 00:00:00 2001 From: SamyOubouaziz Date: Thu, 3 Apr 2025 17:21:56 +0200 Subject: [PATCH 3/8] docs(SRV): update --- .../how-to/build-push-container-image.mdx | 100 ++++++++++++++---- 1 file changed, 80 insertions(+), 20 deletions(-) diff --git a/pages/serverless-containers/how-to/build-push-container-image.mdx b/pages/serverless-containers/how-to/build-push-container-image.mdx index 2519b45e0d..c44d9b4d55 100644 --- a/pages/serverless-containers/how-to/build-push-container-image.mdx +++ b/pages/serverless-containers/how-to/build-push-container-image.mdx @@ -1,10 +1,10 @@ --- meta: - title: How to create a Dockerfile - description: Learn how to create a Dockerfile for deploying containerized applications. + 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 create a Dockerfile - paragraph: Learn how to create a Dockerfile to containerize your applications for deployment on Scaleway or any other containerized platform. + 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 @@ -16,12 +16,72 @@ categories: This page explains how to create a simple Dockerfile to containerize your applications for deployment using Scaleway Serverless Containers. -## How to Write a Dockerfile + -1. Create a file named `Dockerfile` in your project directory. +- 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: + + +```dockerfile +# Use the official Nginx image +FROM nginx:alpine + +# Create simple HTML content directly in the Dockerfile +RUN echo "Demo

Hello Scaleway Serverless Containers!

Served by Nginx

" > /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;"] +``` +
+ +```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('

Hello from Scaleway Serverless!

');\n});\n\napp.listen(port, () => {\n console.log(`Server running on port \${port}`);\n});" > server.js + +# Start the application +CMD ["npm", "start"] +``` +
+ +```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\n@app.route('/')\ndef hello():\n return '

Hello from Flask on Scaleway Serverless!

'\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 +``` +
+
```dockerfile # Use an official base image FROM python:3.9-slim @@ -51,26 +111,26 @@ CMD ["python", "app.py"] 2. Run the following command to build your Docker image: -```bash -docker build -t my-application . -``` + ```bash + docker build -t my-application . + ``` -3. Log in to your Scaleway account in the terminal: +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 -u --password-stdin -``` + ``` + 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 -``` + ``` + 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 -``` + ``` + 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/) \ No newline at end of file +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. From 2980a76df5a280a2aae53180c49c72c83fc34585 Mon Sep 17 00:00:00 2001 From: SamyOubouaziz Date: Thu, 3 Apr 2025 17:24:26 +0200 Subject: [PATCH 4/8] docs(SRV): update --- .../how-to/build-push-container-image.mdx | 22 ------------------- 1 file changed, 22 deletions(-) diff --git a/pages/serverless-containers/how-to/build-push-container-image.mdx b/pages/serverless-containers/how-to/build-push-container-image.mdx index c44d9b4d55..84bbdd8c58 100644 --- a/pages/serverless-containers/how-to/build-push-container-image.mdx +++ b/pages/serverless-containers/how-to/build-push-container-image.mdx @@ -82,28 +82,6 @@ CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 app:app ``` -```dockerfile -# Use an official base image -FROM python:3.9-slim - -# Set the working directory in the container -WORKDIR /app - -# Copy the current directory contents into the container at /app -COPY . /app - -# Install any needed packages specified in requirements.txt -RUN pip install --no-cache-dir -r requirements.txt - -# Make port 80 available to the world outside this container -EXPOSE 80 - -# Define environment variable -ENV NAME World - -# Run app.py when the container launches -CMD ["python", "app.py"] -``` ## How to build and push your image from your dockerfile From b4abcae1b10e3d782fb98b005196153cd2421ba5 Mon Sep 17 00:00:00 2001 From: SamyOubouaziz Date: Mon, 7 Apr 2025 15:27:15 +0200 Subject: [PATCH 5/8] docs(SRV): update --- .../how-to/build-push-container-image.mdx | 83 ++++++++++++------- 1 file changed, 55 insertions(+), 28 deletions(-) diff --git a/pages/serverless-jobs/how-to/build-push-container-image.mdx b/pages/serverless-jobs/how-to/build-push-container-image.mdx index d620927e01..e832350505 100644 --- a/pages/serverless-jobs/how-to/build-push-container-image.mdx +++ b/pages/serverless-jobs/how-to/build-push-container-image.mdx @@ -22,28 +22,55 @@ This page explains how to create a simple Dockerfile to containerize your applic 2. Add the following content to your Dockerfile, adjusting the base image and commands according to your application: + + ```dockerfile -# Use an official base image -FROM python:3.9-slim +# Use the official Golang image to create a build artifact. +FROM golang:1.24-alpine AS builder -# Set the working directory in the container -WORKDIR /app +# Create the main.go file with the Go source code +RUN echo 'package main -# Copy the current directory contents into the container at /app -COPY . /app +import "fmt" -# Install any needed packages specified in requirements.txt -RUN pip install --no-cache-dir -r requirements.txt +func main() { + fmt.Println("Hello from Scaleway Serverless Jobs!") +}' > main.go -# Make port 80 available to the world outside this container -EXPOSE 80 +# Build the Go app +RUN go build -o main . -# Define environment variable -ENV NAME World +# Start a new stage from scratch +FROM alpine:latest -# Run app.py when the container launches -CMD ["python", "app.py"] +# Copy the Pre-built binary file from the previous stage +COPY --from=builder /app/main . + +# Command to run the executable +CMD ["./main"] +``` + + +```dockerfile +FROM python:3.13-slim + +# Single-line Python script as entrypoint +CMD ["python", "-c", "print('Hello from Scaleway Serverless Jobs!')"] +``` + + +```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"] ``` + + ## How to build and push your image from your dockerfile @@ -51,26 +78,26 @@ CMD ["python", "app.py"] 2. Run the following command to build your Docker image: -```bash -docker build -t my-application . -``` + ```bash + docker build -t my-application . + ``` -3. Log in to your Scaleway account in the terminal: +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 -u --password-stdin -``` + ``` + 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 -``` + ``` + 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 -``` + ``` + 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/) \ No newline at end of file +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. From 65cd4e46e0948c8469ab0c98273adc6acbc37352 Mon Sep 17 00:00:00 2001 From: SamyOubouaziz Date: Mon, 7 Apr 2025 15:34:12 +0200 Subject: [PATCH 6/8] docs(SRV): update --- pages/serverless-jobs/how-to/build-push-container-image.mdx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pages/serverless-jobs/how-to/build-push-container-image.mdx b/pages/serverless-jobs/how-to/build-push-container-image.mdx index e832350505..400563a15d 100644 --- a/pages/serverless-jobs/how-to/build-push-container-image.mdx +++ b/pages/serverless-jobs/how-to/build-push-container-image.mdx @@ -84,19 +84,19 @@ CMD ["./main"] 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 ``` From 28a7b7ec576d836f4f732d94d62ecf2770a3f63d Mon Sep 17 00:00:00 2001 From: SamyOubouaziz Date: Mon, 7 Apr 2025 16:50:03 +0200 Subject: [PATCH 7/8] docs(SRV): update --- .../serverless-jobs/how-to/build-push-container-image.mdx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pages/serverless-jobs/how-to/build-push-container-image.mdx b/pages/serverless-jobs/how-to/build-push-container-image.mdx index 400563a15d..ecdf705de2 100644 --- a/pages/serverless-jobs/how-to/build-push-container-image.mdx +++ b/pages/serverless-jobs/how-to/build-push-container-image.mdx @@ -1,10 +1,10 @@ --- meta: - title: How to create a Dockerfile - description: Learn how to create a Dockerfile for deploying containerized applications. + 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: How to create a Dockerfile - paragraph: Learn how to create a Dockerfile to containerize your applications for deployment on Scaleway or any other containerized platform. + 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 From 9e0011b3dc6ba3ac105668f07f6b8927509c02c1 Mon Sep 17 00:00:00 2001 From: SamyOubouaziz Date: Tue, 8 Apr 2025 15:49:00 +0200 Subject: [PATCH 8/8] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Néda <87707325+nerda-codes@users.noreply.github.com> Co-authored-by: Rowena Jones <36301604+RoRoJ@users.noreply.github.com> --- .../how-to/build-push-container-image.mdx | 6 +++--- .../serverless-jobs/how-to/build-push-container-image.mdx | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pages/serverless-containers/how-to/build-push-container-image.mdx b/pages/serverless-containers/how-to/build-push-container-image.mdx index 84bbdd8c58..bbd23c2ad1 100644 --- a/pages/serverless-containers/how-to/build-push-container-image.mdx +++ b/pages/serverless-containers/how-to/build-push-container-image.mdx @@ -20,7 +20,7 @@ This page explains how to create a simple Dockerfile to containerize your applic - 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. +- 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/) @@ -83,7 +83,7 @@ CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 app:app -## How to build and push your image from your dockerfile +## How to build and push your image from your Dockerfile 1. Open a terminal and navigate to the directory containing your Dockerfile. @@ -93,7 +93,7 @@ CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 app:app 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: +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: ``` docker login rg.fr-par.scw.cloud/your-container-registry-namespace -u nologin --password-stdin <<< "$SCW_SECRET_KEY" diff --git a/pages/serverless-jobs/how-to/build-push-container-image.mdx b/pages/serverless-jobs/how-to/build-push-container-image.mdx index ecdf705de2..fae7a9fddb 100644 --- a/pages/serverless-jobs/how-to/build-push-container-image.mdx +++ b/pages/serverless-jobs/how-to/build-push-container-image.mdx @@ -1,9 +1,9 @@ --- meta: - title: ow to build and push a container image + 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 Jobs. content: - h1: ow to build and push a container image + 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 Jobs. tags: create dockerfile containerize application deployment scaleway dates: @@ -72,7 +72,7 @@ CMD ["./main"] -## How to build and push your image from your dockerfile +## How to build and push your image from your Dockerfile 1. Open a terminal and navigate to the directory containing your Dockerfile. @@ -82,7 +82,7 @@ CMD ["./main"] 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: +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. ```sh docker login rg.fr-par.scw.cloud/your-container-registry-namespace -u nologin --password-stdin <<< "$SCW_SECRET_KEY"