|
| 1 | +--- |
| 2 | +meta: |
| 3 | + title: How to create a Dockerfile |
| 4 | + description: Learn how to create a Dockerfile for deploying containerized applications. |
| 5 | +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. |
| 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 | +```dockerfile |
| 26 | +# Use an official base image |
| 27 | +FROM python:3.9-slim |
| 28 | + |
| 29 | +# Set the working directory in the container |
| 30 | +WORKDIR /app |
| 31 | + |
| 32 | +# Copy the current directory contents into the container at /app |
| 33 | +COPY . /app |
| 34 | + |
| 35 | +# Install any needed packages specified in requirements.txt |
| 36 | +RUN pip install --no-cache-dir -r requirements.txt |
| 37 | + |
| 38 | +# Make port 80 available to the world outside this container |
| 39 | +EXPOSE 80 |
| 40 | + |
| 41 | +# Define environment variable |
| 42 | +ENV NAME World |
| 43 | + |
| 44 | +# Run app.py when the container launches |
| 45 | +CMD ["python", "app.py"] |
| 46 | +``` |
| 47 | + |
| 48 | +## How to build and push your image from your dockerfile |
| 49 | + |
| 50 | +1. Open a terminal and navigate to the directory containing your Dockerfile. |
| 51 | + |
| 52 | +2. Run the following command to build your Docker image: |
| 53 | + |
| 54 | +```bash |
| 55 | +docker build -t my-application . |
| 56 | +``` |
| 57 | + |
| 58 | +3. Log in to your Scaleway account in the terminal: |
| 59 | + |
| 60 | +``` |
| 61 | +docker login -u <your-email> --password-stdin |
| 62 | +``` |
| 63 | + |
| 64 | +4. Tag your Docker image so it matches your Scaleway registry's format: |
| 65 | + |
| 66 | +``` |
| 67 | +docker tag my-application |
| 68 | +``` |
| 69 | + |
| 70 | +5. Push the Docker image to the Scaleway Container Registry: |
| 71 | + |
| 72 | +``` |
| 73 | +docker push |
| 74 | +``` |
| 75 | + |
| 76 | +You can now access your container image from the [Scaleway Container Registry](https://console.scaleway.com/) |
0 commit comments