Suchen

Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.

Chapter 13. Creating a Container with an Application

download PDF

This section describes how to create a docker-formatted container image from a locally built application. Making your application available as a container is advantageous when you wish to use orchestration for deployment. Alternatively, containerizing effectively solves conflicts of dependencies.

Prerequisites

  • Understanding of containers
  • An application built locally from source

Procedure

  1. Decide which base image to use.

    Note

    Red Hat recommends starting with a base image that uses Red Hat Enterprise Linux as its foundation. Refer to the Base Image in the Red Hat Container Catalog for further information.

  2. Create a workspace directory.
  3. Prepare your application as a directory containing all of the application’s required files. Place this directory inside the workspace directory.
  4. Write a Dockerfile that describes the steps required to create the container.

    Refer to the Dockerfile Reference for information about how to create a Dockerfile that includes your content, sets default commands to run, and opens necessary ports and other features.

    This example shows a minimal Dockerfile that contains the my-program/ directory:

    FROM registry.access.redhat.com/rhel7
    USER root
    ADD my-program/ .

    Place this Dockerfile into the workspace directory.

  5. Build a container image from the Dockerfile:

    # docker build .
    (...)
    Successfully built container-id

    During this step, note the container-id of the newly created container image.

  6. Add a tag to the image to identify the registry where you want the container image to be stored. See Getting Started with Containers — Tagging Images.

    # docker tag container-id registry:port/name

    Replace container-id with the value shown in the output of the previous step.

    Replace registry with the address of the registry you want to push the image to, port with the port of the registry (omit if not needed), and name with the name of the image.

    For example, if you are running a registry using the docker-distribution service on your local system with an image named myimage, the tag localhost:5000/myimage would enable that image to be pushed to the registry.

  7. Push the image to the registry so it can be pulled from that registry later.

    # docker push registry:port/name

    Replace the tag parts with the same values as the ones used in the previous step.

    To run your own Docker registry, see Getting Started with Containers — Working with Docker registries.

Additional Resources

Red Hat logoGithubRedditYoutubeTwitter

Lernen

Testen, kaufen und verkaufen

Communitys

Über Red Hat Dokumentation

Wir helfen Red Hat Benutzern, mit unseren Produkten und Diensten innovativ zu sein und ihre Ziele zu erreichen – mit Inhalten, denen sie vertrauen können.

Mehr Inklusion in Open Source

Red Hat hat sich verpflichtet, problematische Sprache in unserem Code, unserer Dokumentation und unseren Web-Eigenschaften zu ersetzen. Weitere Einzelheiten finden Sie in Red Hat Blog.

Über Red Hat

Wir liefern gehärtete Lösungen, die es Unternehmen leichter machen, plattform- und umgebungsübergreifend zu arbeiten, vom zentralen Rechenzentrum bis zum Netzwerkrand.

© 2024 Red Hat, Inc.