Containers are an important part of modern computing, for hosting, for application development, and even as an alternative to virtualization. The infrastructure supporting containers has been refined and developed since the early days, so if you've been holding off on adopting containers, you might be pleasantly surprised at how easy the daemonless Podman engine makes it to build, run, and manage containers and pods.
Containers interface directly with Linux kernel abilities like cgroups and namespaces. Running a container literally uses your existing kernel to run additional Linux systems inside your existing Linux system.
A kernel namespace is a construct that helps Linux keep track of what processes belong together. It's a little like the red ropes used to create a queue leading into a busy theater. There's not actually a difference between processes in one queue and another, but it's helpful to cordon them off from one another. Keeping them separate is the key to declaring one group of processes a "container" and the other group of processes your OS.
Install Podman
If Podman isn't already installed on your Linux system, install it using your package manager:
$ sudo dnf install podman
To test your install, try running a simple container image:
$ podman run busybox echo "hello"
hello
You've just downloaded a container image that provides the minimal busybox shell. Podman instantiated a container, which in turn ran the echo command and then ended its process. That's a common workflow for containers. You're often going to want a more complex container than a minimal shell, and you can define what's in a container by writing a Containerfile.
Write a Containerfile
You can define what software is included in a container image by writing a Containerfile. This file, which must be named Containerfile (or Dockerfile, for compatibility purposes), lists what base image you want to use, plus additional commands to run before the container is launched.
As an example, suppose you need to run a web server in a container. There are several container images already built for that purpose, but this example steps through building a very basic one as a demonstration. For production use, you can use an existing container that integrates SSL, a database, and other important features.
1. Find a base image
Container images are a little like the install image for an operating system. You don't install a container image, but it's the blueprint used when you launch a container. It's possible to build a container image from scratch, but it's easier to use a reliable base image that a trusted source has already prepared.
The Red Hat Universal Base Image (UBI) offers a way to build your container images on a foundation of Red Hat Enterprise Linux software.
Open a text editor and create a file called Containerfile, and enter these three lines to set what image you're building upon, who to contact with questions, and what user is active within the container:
FROM ubi9:latest
MAINTAINER Tux
tux@example.com
USER root
2. Define software installations and configuration
Most container images are minimal by design. To keep file sizes small, and resource requirements and attack vectors minimal, your container must incorporate only what's necessary for it to perform its stated task.
In this example, you only want to run a web server, so all you need to install is the httpd package (along with whatever dependencies it automatically brings in). You must also expose port 80, the port a web server runs on by default.
In your Containerfile, add these lines:
# Install
RUN dnf install httpd -y
EXPOSE 80
You must also set some environment variables within the container so the httpd server uses the correct paths for its configuration files and logs:
ENV HTTPD_APP_ROOT=${APP_ROOT} \
HTTPD_CONFIGURATION_PATH=${APP_ROOT}/etc/httpd.d \
HTTPD_MAIN_CONF_PATH=/etc/httpd/conf \
HTTPD_MAIN_CONF_MODULES_D_PATH=/etc/httpd/conf.modules.d \
HTTPD_MAIN_CONF_D_PATH=/etc/httpd/conf.d \
HTTPD_VAR_RUN=/var/run/httpd \
HTTPD_DATA_PATH=/var/www \
HTTPD_DATA_ORIG_PATH=/var/www \
HTTPD_LOG_PATH=/var/log/httpd
Next, adjust the server's name in the httpd configuration files. In this example, you can use localhost
because you're not actually setting up a domain:
RUN sed -i \
's/#ServerName/ServerName/' $HTTPD_MAIN_CONF_PATH/httpd.conf RUN sed -i \
's/www\.example\.com/localhost/g' $HTTPD_MAIN_CONF_PATH/httpd.conf
All of these attributes are set as part of the container's configuration during the build process. When a container is spawned from this image, everything you've entered so far are its default settings.
3. Define launch action
Items marked as RUN occur during the image build process, but items marked as CMD run after a container has been launched. In this example, you want the container to start the httpd server at launch.
Add these lines to your In your Containerfile:
# Launch
CMD ["/usr/sbin/httpd", "-DFOREGROUND"]
Save the file, because you're ready to build!
Build your image
Build the container you've defined in your Containerfile using the podman command. You must be in the directory containing your Containerfile. Note that the command ends in a single dot (.) indicating that podman
must proceed from the current directory:
$ podman build --tag myfirstcontainer .
Run your image in a container
When you initially tested podman
to run a sample BusyBox shell, the container launched, executed a command, and then terminated. That works for a simple demonstration of a foreground command like echo
, but it's not useful behavior for a web server meant to run as a background service. You need this container to initialize and continue to run so you have time to open a web browser and look at the page.
To run the container with its port 80 mapped to your localhost port 8080, in a detached state (so you get your terminal prompt back):
$ podman run --detach --name mywebcontainer \--publish 8080:80 mywebcontainer
Now open a web browser and navigate to http://localhost:8080 to see the default web page provided by your web server.

Containers like commands
Containers may feel mysterious if you're new to them, but actually, they're no different than your existing Linux system. They are literally processes running on your system, without the cost or barrier of an emulated environment or virtual machine. All that separates a container from your OS are kernel namespaces, so they're really just native processes with different labels on them. Podman makes this more evident than ever, and once you configure Podman to be a rootless command, containers feel more like commands than virtual environments. Podman makes containers and pods easy, so give it a try.
Get Started
product trial
Red Hat OpenShift Container Platform | 제품 체험판
저자 소개
Seth Kenlon is a Linux geek, open source enthusiast, free culture advocate, and tabletop gamer. Between gigs in the film industry and the tech industry (not necessarily exclusive of one another), he likes to design games and hack on code (also not necessarily exclusive of one another).
유사한 검색 결과
채널별 검색
오토메이션
기술, 팀, 인프라를 위한 IT 자동화 최신 동향
인공지능
고객이 어디서나 AI 워크로드를 실행할 수 있도록 지원하는 플랫폼 업데이트
오픈 하이브리드 클라우드
하이브리드 클라우드로 더욱 유연한 미래를 구축하는 방법을 알아보세요
보안
환경과 기술 전반에 걸쳐 리스크를 감소하는 방법에 대한 최신 정보
엣지 컴퓨팅
엣지에서의 운영을 단순화하는 플랫폼 업데이트
인프라
세계적으로 인정받은 기업용 Linux 플랫폼에 대한 최신 정보
애플리케이션
복잡한 애플리케이션에 대한 솔루션 더 보기
오리지널 쇼
엔터프라이즈 기술 분야의 제작자와 리더가 전하는 흥미로운 스토리
제품
- Red Hat Enterprise Linux
- Red Hat OpenShift Enterprise
- Red Hat Ansible Automation Platform
- 클라우드 서비스
- 모든 제품 보기
툴
체험, 구매 & 영업
커뮤니케이션
Red Hat 소개
Red Hat은 Linux, 클라우드, 컨테이너, 쿠버네티스 등을 포함한 글로벌 엔터프라이즈 오픈소스 솔루션 공급업체입니다. Red Hat은 코어 데이터센터에서 네트워크 엣지에 이르기까지 다양한 플랫폼과 환경에서 기업의 업무 편의성을 높여 주는 강화된 기능의 솔루션을 제공합니다.