-
Notifications
You must be signed in to change notification settings - Fork 259
docs(SRV): add build push image doc for cass & jobs MTA-5835 #4767
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+225
−0
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
dff50fe
docs(SRV): add build push image doc for cass & jobs MTA-5835
SamyOubouaziz c3b8817
docs(SRV): update
SamyOubouaziz d1ed2e0
docs(SRV): update
SamyOubouaziz 2980a76
docs(SRV): update
SamyOubouaziz b4abcae
docs(SRV): update
SamyOubouaziz 65cd4e4
docs(SRV): update
SamyOubouaziz 28a7b7e
docs(SRV): update
SamyOubouaziz 9e0011b
Apply suggestions from code review
SamyOubouaziz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
pages/serverless-containers/how-to/build-push-container-image.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
SamyOubouaziz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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: | ||
SamyOubouaziz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ``` | ||
| 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
103
pages/serverless-jobs/how-to/build-push-container-image.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| --- | ||
| meta: | ||
| title: ow to build and push a container image | ||
SamyOubouaziz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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 | ||
SamyOubouaziz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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 | ||
SamyOubouaziz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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: | ||
SamyOubouaziz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```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. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.