Get started building Python application containers on Red Hat Enterprise Linux Atomic Host in under 15 minutes.
In this tutorial, you will see how to deploy a Python 3 application in containers on Red Hat Enterprise Linux Atomic Host. Atomic Host is a secure, minimal-footprint OS optimized to run Linux containers.
You will need to have Red Hat Enterprise Linux Atomic Host installed on a virtual (or physical) machine. You will also need a current Red Hat subscription that allows you to download software and updates from Red Hat.
[Keep or delete??] If you don’t have a Red Hat Enterprise Linux subscription, you can try it for free. Get started with an evaluation at https://access.redhat.com/products/red-hat-enterprise-linux/evaluation. Downloading and installing Atomic Host requires a Red Hat Enterprise Linux Server Evaluation. Generally, developers should select the Red Hat Enterprise Linux Developer Workstation option to ensure your evaluation includes Red Hat Software Collections and the Red Hat Developer Toolset, however that evaluation does not include Atomic Host. FIXME
If you are interested in purchasing a Red Hat subscription for development, the Red Hat Developer Suite is an affordable choice that includes Red Hat Enterprise Linux Server, Atomic Host, Red Hat Developer Toolset and Software Collections.
The best way to get started with Atomic Host depends on what OS you are using on your development system:
-
If you are using Microsoft Windows, Apple Mac OS X, or Fedora Linux, the Red Hat Container Development Kit (CDK) provides pre-built virtual machines (VMs) for both Red Hat Enterprise Linux and the Atomic Host edition. A paid subscription, such as Red Hat Developer Suite, is required to download the CDK. Follow the CDK Installation Guide for your OS:
-
If you are already running Red Hat Enterprise Linux 7 server, you can run this tutorial directly on your system after configuring your system to run
docker
. See Getting Docker on RHEL 7 in the article Get Started with Docker Formatted Container Images on Red Hat Systems. -
If you’d like to install Atomic on a physical machine or build your virtual machine, see Get Started with Red Hat Enterprise Linux Atomic Host. [NOTE: FIXME: This should be a link to the Atomic Get Started guide that is part of this "get started" site, not the KB article, https://access.redhat.com/articles/rhel-atomic-getting-started, Note: the names are too similar need to come up with something different.]
-
[FIXME/TODO] - Is there a documented path for running Atomic Host under KVM on RHEL? There is a qcow2 download that is listed as a "Cloud Image" instead of a "KVM image" the way it is listed for RHEL server/workstation. https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Installation_Guide/chap-atomic-virtualization.html
Atomic Host is specifically optimized for the deployment of Linux containers in environments such as Infrastructure as a Service (IaaS) clouds. It’s minimal footprint contains only the software needed to efficiently host containers. Since it does not include a graphical user interface, or development tools, Atomic Host isn’t suited for software development activities. Instead, developers should use Red Hat Enterprise Linux which is design to suit many purposes including desktop and server installations. See Get Started with Docker Formatted Container Images on Red Hat Systems. After an application has been developed and packaged in a container, developers may want to test them on Atomic Host. Atomic Host can be helpful for developers that are creating continuous integration / continuous delivery (CI/CD) environments.
If you encounter difficulties at any point in this tutorial, see Troubleshooting and FAQ.
In this step, you will download and install the latest updates from Red Hat for your Atomic Host installation. In the process, you will verify that your system has a current Red Hat subscription and is able to receive updates.
Note: If you are not using Atomic Host and following this tutorial on Red Hat Enterprise Linux Server, see Getting Docker on RHEL 7 in the article Get Started with Docker Formatted Container Images on Red Hat Systems.
The process for installing updates on Atomic Host is different than other Red Hat systems. On Atomic Host, updates are applied atomically in a single indivisible step. Likewise, updates can also be rolled back in a single step. Most of the file systems on Atomic Host are mounted read-only, only /etc
and /var
are writable. Yum is not used for installing updates or software. Instead, the rpm-ostree
system is used for installing updates. Software is installed using docker containers.
Login to your virtual (or physical) machine running Atomic Host as the root user, or use su
or sudo bash
to start a root session. If you haven’t registered your system you can do it with subscription-manager
. Use same the username and password that use for logging into the Red Hat Customer Portal, access.redhat.com.
# subscription-manager register --username=<username> --auto-attach
To install the latest updates, use the following command:
# atomic host upgrade
To see the new version that got installed, use the following command:
# atomic host status
The asterisk at the beginning of the line indicates which version the system is current running. To make the update take effect, you must reboot the system.
# systemctl reboot
After the system reboots atomic host status
should confirm that the system is running the latest version.
If you encounter difficulties at any point, see Troubleshooting and FAQ.
This step will download and install Python 3 using a container from the Red Hat container registry. Installing the Python 3 container will make Python 3 available for use by other containers on your system. Because containers run in isolated environments, your host system will not altered by the installation. You must use docker
commands to use or view the container’s content.
The commands shown in this section can be used for downloading and installing other containers, such as application containers you build. Containers can specify that they require other containers to be installed, which can happen automatically. When you build an application in a container that uses Python 3, you can specify that it requires Python 3 in the Dockerfile
that is used to describe and build your container. Then when someone installs your container, their system will automatically download the required Python 3 container directly from the Red Hat container registry.
The Python 3 container is part of Red Hat Software Collections which provides the latest development technologies for Red Hat Enterprise Linux. Access to the Red Hat Software Collections (RHSCL) is included with many Red Hat Enterprise Linux (RHEL) subscriptions. For more information about which subscriptions include RHSCL, see How to use Red Hat Software Collections (RHSCL) or Red Hat Developer Toolset (DTS).
Note: If you are not using Atomic Host and following this tutorial on Red Hat Enterprise Linux Server, you should have already installed docker
. See Getting Docker on RHEL 7 in the article Get Started with Docker Formatted Container Images on Red Hat Systems.
If you don’t have a root session running on your container host, login as the root user, or use su
or sudo bash
to start a root session.
To download and install the Python 3 container, use the following command:
docker pull registry.acess.redhat.com/openshift3/python-33-rhel7
The docker images
command should show the container image that was installed as well as any others that are on your system.
# docker images
Now start a bash shell inside the Python 3 container to have a look around. The shell prompt changes, which is an indication that you are typing at the shell inside the container. A ps -ef
shows the only thing running inside the container is bash
and ps
. Type exit
to leave the container’s bash shell.
# docker run -it openshift3/python-33-rhel7 /bin/bash
bash-4.2$ which python3
/opt/rh/python33/root/usr/bin/python3
bash-4.2$ python3 --version
Python 3.3.2
bash-4.2$ ps -ef
UID PID PPID C STIME TTY TIME CMD
default 1 0 0 21:56 ? 00:00:00 /bin/bash
default 11 1 0 21:58 ? 00:00:00 ps -ef
bash-4.2$ exit
The above docker run
command created a container to run your command, keep any state, and isolate it from the rest of the system. You can view the list of running containers with docker ps
. To see all of the containers that have been created, included those that have exited use docker ps -a
.
You can restart the container that was created above with docker start
. Containers are referred to by name. Docker will automatically generate a name if you don’t provide one. Once the container has been restarted, docker attach
will let you interact with the shell running inside of it. See the following example:
# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c3e47aafe6d1 openshift3/python-33-rhel7 "/bin/bash" 23 seconds ago Exited (0) 19 seconds ago high_kowalevski
[root@rhdsrvr httpd-project]# docker start high_kowalevski
high_kowalevski
[root@rhdsrvr httpd-project]# docker attach high_kowalevski
At this point you are connected to the running shell inside the container. When you attach you won’t see the command prompt, so hit enter get it to print another one.
bash-4.2$ ps -ef
UID PID PPID C STIME TTY TIME CMD
default 1 0 0 14:53 ? 00:00:00 /bin/bash
default 10 1 0 14:53 ? 00:00:00 ps -ef
bash-4.2$ exit
Since bash was told to exit
, the container will no longer be running. This can be verified with docker ps -a
. Containers that are no longer needed can be cleaned up with docker rm <container-name>
.
docker rm high_kowalevski
To see what other containers are available in the Red Hat container registry, use one or more of the following searches:
# docker search registry.redhat.com/openshift3
# docker search registry.redhat.com/jboss
# docker search registry.redhat.com/rhel
If you need help, see Troubleshooting and FAQ.
In this step, you will create a tiny Hello World container that uses Python 3 as a web server. Once created, the container can be run on other systems that have docker
installed. You will need to create several files, including a Dockerfile
which describes the container in an empty directory using your favorite editor. You don’t need to be running under the root user to create the files, but you will need root privileges to run the docker
commands.
First, create an empty directory, and then create a file named index.html
with the following contents:
<html>Hello, Red Hat Developers World~</html>
Now in the same directory, create a file named Dockerfile
with the following contents. Change the MAINTAINER
line to have your name and email address.
FROM openshift3/python-33-rhel7:latest MAINTAINER Your Name "[email protected]" EXPOSE 8000 COPY . /opt/openshift/src CMD /bin/bash -c 'python3 web.py'
Create the file web.py
with the following contents:
# # A very simple Python HTTP server # import http.server import socketserver PORT = 8000 Handler = http.server.SimpleHTTPRequestHandler httpd = socketserver.TCPServer(("", PORT), Handler) print("serving at port", PORT) httpd.serve_forever()
Now build the container image with the following command. You will need to be root using su
or sudo
in the directory you created that above that contains Dockerfile
and index.html
.
# docker build -t myname/pythonweb .
You can see the container image that was created using the following command.
# docker images
Now run the container using the following command. The Python 3 http.server module will create a tiny web server listening on port 8000 inside the container. The run
command will map port 8000 on the host machine to port 8000 inside the container.
# docker run -d -p 8000:8000 myname/pythonweb
The run command returned a ID for the container which you can ignore. To check that the container is running use the following command. Take note of the name docker assigned to the running container.
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7d3b47bfded6 myname/pythonweb "/bin/sh -c '/bin/ba 18 seconds ago Up 17 seconds 8080/tcp, 0.0.0.0:8000->8000/tcp grave_brown
Use curl
to access the Python web server:
# curl http://localhost:8000/
<html>Hello, Red Hat Developers World!</html>
When you are done, stop the running container with the following command using the name obtained from running docker ps
# docker kill grave_brown
Get Started with Docker Formatted Container Images on Red Hat Systems — This article explains how to install docker on Red Hat Enterprise Linux and Atomic Host. It also provides a more extensive set examples than this tutorial.
Getting Started with Red Hat Enterprise Linux Atomic Host — This article provides an overview of Atomic Host, how it is different, and how to use it.
*Red Hat Enterprise Linux 7.1 Release Notes — includes information on recent updates to Atomic Host and Docker formatted Linux containers
Red Hat delivers the resources and ecosystem of experts to help you be more productive and build great solutions. Register for free at developers.redhat.com.
Follow the Red Hat Developer Blog
http://developerblog.redhat.com/
-
My system is unable to download updates from Red Hat.
I don’t have a current Red Hat subscription, can I get an evaluation?
If you don’t have a Red Hat Enterprise Linux subscription, you can try it for free. Get started with an evaluation at https://access.redhat.com/products/red-hat-enterprise-linux/evaluation. Developers should select the Red Hat Enterprise Linux Developer Workstation option to ensure your evaluation includes additional tools from the Red Hat Developer Toolset and Red Hat Software Collections.
-
When I start Atomic Host, I don’t see a graphical environment.
Atomic Host is specifically optimized for the deployment of Linux containers in environments such as Infrastructure as a Service (IaaS). It’s minimal footprint contains only the software needed to efficiently host containers. Since it does not include a graphical user interface, or development tools, Atomic Host isn’t suited for software development activities. Instead, developers should use Red Hat Enterprise Linux which is design to suit many purposes including desktop and server installations. See Get Started with Docker Formatted Container Images on Red Hat Systems. After an application has been developed and packaged in a container, developers may want to test them on Atomic Host. Atomic Host can be helpful for developers that are creating continuous integration / continuous delivery (CI/CD) environments.
-
How do I tell if a container image with a new version of Python is available?
How can I see what other container images are available?
I can’t find the container mentioned in this tutorial, how can I tell if the name changed?
To see what other containers are available in the Red Hat container registry, use one or more of the following searches:
# docker search registry.redhat.com/openshift3
# docker search registry.redhat.com/jboss
# docker search registry.redhat.com/rhel
+ 4. Can I run and build docker containers on Red Hat Enterprise Linux?
+ Red Hat Enterprise Linux includes docker, but it is not installed by default. See Getting Docker on RHEL 7 in the article Get Started with Docker Formatted Container Images on Red Hat Systems.
+ 5. Where can I learn more about delivering applications with Linux containers?
+ If you haven’t already joined the Red Hat Developers program, sign up at developers.redhat.com. Membership is free.+ Recommended Practices for Container Development and many other container articles are available from the Red Hat Customer Portal.+ If you are a Red Hat Technology Partner, visit the Container Zone at the Red Hat Connect for Technology Partners web site.