By clicking or navigating this website site, you agree to allow our collection of information on Scaleway to offer you an optimal user experience and to keep track of statistics through cookies. Learn more about our Cookie Policy.

Getting started with the Docker InstantApp

Getting Started with the Docker InstantApp

This page shows you how to use the Docker InstantApp on your cloud instance.

Once logged in, you will be greeted by the following screen showing some parameters about the instance and the Docker version already pre-installed on the instance:

Building your First Container

Docker allows you to ship applications in containers. Containers are standardized units of software that bundle the applications code and all its dependencies into one package, so the application runs quickly and reliably from one computing environment to another.

Docker can build images automatically by reading the instructions from a Dockerfile. This is a text document that contains all the commands a user would execute on the command line to assemble an image.

Create a new Dockefile for a small Python web application with Flask, that will run on the instance:

1 . Create a new directory to develop your environment

mkdir my-application

2 . Enter into the directory

cd my-application

3 . Create a new file, called Dockerfile, copy & paste the following content into it and save the file

# Use an official Python runtime as a parent image
FROM python:3.7-slim
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
ADD . /app
# Install the Flask framework
RUN pip install --trusted-host pypi.python.org Flask
# 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"]

4 . Now as the Dockerfile is ready, it is time to create the application. Open a text editor, copy paste the following content and save the file as app.py.

Running the Application

Run the application with the -p option to map the port 4000 of your instance to port 80 of the container:

docker run -p 4000:80 helloworld

A message that the application called app is running is shown:

* Serving Flask app "app" (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://0.0.0.0:80/ (Press CTRL+C to quit)

The message displays the information, that the application is running on port 80.

Remember, this is the internal port of the container and to reach the application type http://your_instances_ip:4000 in the address bar of your browser:

The application displays the internal hostname of the container and retrieves the word “World” from the environment variable that was set in the Dockerfile.

Sharing the Application

Docker allows easily to ship images to a registry to share it with others.

In this example, the public docker registry is used, but it also possible to set up a private registry to distribute the image on your infrastructure.

It is required to have a Docker account for this part of the tutorial. If you do not have one, you can create an account at hub.docker.com.

1 . Login into the Docker registry:

docker login

To associate a local image with a repository on a registry, you have to use the notation username/repository:tag.

The tag is not mandatory, but recommended as it is the mechanism that registries use to give Docker images a version.

To push your image you have to run docker tag with your username, repository, and tag, so your image uploads to the desired destination.

2 . Tag the image:

docker tag imagename username/repository:tag

3 . Publish your image:

docker push username/repository:tag

Once the image has been pushed to Docker Hub it will be publicly available and you can see the image with its pull command in your account.

Pulling and Running an Image from a Remote Repository

As your image is available on the Docker Hub now, you can run it from everywhere

docker run -p 4000:80 username/repository:tag

If the image is not available yet on the local machine, Docker will download it from the registry.

No matter on which machine you run it, it will always run in the same environment that you have configured when you have built the image.