You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pages/serverless-jobs/how-to/build-push-container-image.mdx
+55-28Lines changed: 55 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,55 +22,82 @@ This page explains how to create a simple Dockerfile to containerize your applic
22
22
23
23
2. Add the following content to your Dockerfile, adjusting the base image and commands according to your application:
24
24
25
+
<Tabsid="dockerfile-examples">
26
+
<TabsTablabel="Go">
25
27
```dockerfile
26
-
# Use an official base image
27
-
FROMpython:3.9-slim
28
+
# Use the official Golang image to create a build artifact.
29
+
FROMgolang:1.24-alpine AS builder
28
30
29
-
#Set the working directory in the container
30
-
WORKDIR /app
31
+
#Create the main.go file with the Go source code
32
+
RUN echo 'package main
31
33
32
-
# Copy the current directory contents into the container at /app
33
-
COPY . /app
34
+
import "fmt"
34
35
35
-
# Install any needed packages specified in requirements.txt
36
-
RUN pip install --no-cache-dir -r requirements.txt
36
+
func main() {
37
+
fmt.Println("Hello from Scaleway Serverless Jobs!")
38
+
}' > main.go
37
39
38
-
#Make port 80 available to the world outside this container
39
-
EXPOSE 80
40
+
#Build the Go app
41
+
RUN go build -o main .
40
42
41
-
#Define environment variable
42
-
ENV NAME World
43
+
#Start a new stage from scratch
44
+
FROM alpine:latest
43
45
44
-
# Run app.py when the container launches
45
-
CMD ["python", "app.py"]
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
+
<TabsTablabel="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
+
<TabsTablabel="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"]
46
71
```
72
+
</TabsTab>
73
+
</Tabs>
47
74
48
75
## How to build and push your image from your dockerfile
49
76
50
77
1. Open a terminal and navigate to the directory containing your Dockerfile.
51
78
52
79
2. Run the following command to build your Docker image:
53
80
54
-
```bash
55
-
docker build -t my-application .
56
-
```
81
+
```bash
82
+
docker build -t my-application .
83
+
```
57
84
58
-
3.Log in to your Scaleway account in the terminal:
85
+
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:
You can now access your container image from the [Scaleway Container Registry](https://console.scaleway.com/)
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