DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • Automated Testing Lifecycle
  • Docker and Kubernetes Transforming Modern Deployment
  • Using Open Source for Data Integration and Automated Synchronizations
  • Mastering Node.js: The Ultimate Guide

Trending

  • How To Validate Archives and Identify Invalid Documents in Java
  • The Convergence of Testing and Observability
  • How To Verify Database Connection From a Spring Boot Application
  • Analyzing Stock Tick Data in SingleStoreDB Using LangChain and OpenAI's Whisper
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Your First SLES Container

Your First SLES Container

Using SUSE Linux Enterprise Server to build containers can ensure you're getting legitimate base Docker images to work with, assuming you don't mind a few extra steps.

Jason Evans user avatar by
Jason Evans
·
Apr. 12, 17 · Tutorial
Like (0)
Save
Tweet
Share
9.33K Views

Join the DZone community and get the full member experience.

Join For Free

How do you trust the random Docker hub package out there that may or may not have open-sourced their Dockerfile? It may be fine for experimenting with the Docker platform, but for mission-critical applications, it’s best to know exactly what’s involved.

Docker in SLES gives you all of the power of Docker with the stability and security of Enterprise Linux.

Gathering the Pieces

For this demonstration, you’ll need a registered SUSE Linux Enterprise 12 SP2 server or VM with at least 10GB of storage for your images and containers.

You’ll also need to install the extensions and modules that you’ll want to include in your containers. For example, SDK or the Web and Scripting Module and of course the Containers Module for Docker itself.

Your First Dockerfile

Docker’s official documentation will give you a fantastic overview of the basics of building a Dockerfile. However, building one using SLES adds a few extra steps that ensures you are getting official SUSE base images.

Set Up Docker for the First Time

After finishing the installation of SLES and choosing the modules that you want to add to your Dockerfile, install Docker by simply running:

zypper in docker


Add your User ID to the docker group for easy management of the docker service.

usermod -aG docker <userid>


Log out and then back in to apply the new group membership and then enable and start the docker service.

systemctl enable docker 
systemctl start docker


Adding Images

Most of the time, Docker images are stored in Docker’s own repository and can be downloaded via the docker pull command. SLES base images are downloaded as RPM files and then activated.

jsevans@dockerlab:~> zypper se *-image
Repository 'SLES12-SP2-Updates' is out-of-date. You can run 'zypper refresh' as root to update it.
Repository 'SLE-SDK12-SP2-Updates' is out-of-date. You can run 'zypper refresh' as root to update it.
Loading repository data...
Reading installed packages...

S | Name                   | Summary                                                | Type
--+------------------------+--------------------------------------------------------+-----------
  | sles11sp3-docker-image | SUSE Linux Enterprise Server 11sp3 image for Docker    | package
  | sles11sp4-docker-image | SUSE Linux Enterprise Server 11sp4 image for Docker    | package
  | sles12-docker-image    | SUSE Linux Enterprise Server 12 image for Docker       | package
  | sles12sp1-docker-image | SUSE Linux Enterprise Server 12sp1 image for Docker    | package
i | sles12sp2-docker-image | SUSE Linux Enterprise Server 12sp2 image for Docker    | package


You can download them line any other package from zypper.

zypper in sles12sp2-docker-image


After downloading the images that you want to use, activate them with the sle2docker command.

jsevans@dockerlab:~> sle2docker list
Available pre-built images:
 - sles12sp1-docker.x86_64-1.0.5-Build10.18
 - sles12sp2-docker.x86_64-1.0.0-Build3.2
jsevans@dockerlab:~> sle2docker activate sles12sp1-docker.x86_64-1.0.5-Build10.18
Verifying integrity of the pre-built image
Activating image
suse/sles12sp1:1.0.5 activated


You can now see the new SLES base image when you run the docker images command.

jsevans@dockerlab:~> docker images
REPOSITORY                              TAG                 IMAGE ID            CREATED             SIZE
suse/sles12sp1                          1.0.5               0a4d00395608        33 seconds ago      98.88 MB
suse/sles12sp1                          latest              0a4d00395608        33 seconds ago      98.88 MB


Writing Your Dockerfile

Copy the .repo and .service modules that you will need in the current working directory. In my example, I will be using the Web and Scripting Module.

cp /etc/zypp/repos.d/Web_and_Scripting_Module_12_x86_64\:SLE-Module-Web-Scripting12-Pool.repo <my working directory>

cp /etc/zypp/repos.d/Web_and_Scripting_Module_12_x86_64\:SLE-Module-Web-Scripting12-Updates.repo <my working directory>

cp /etc/zypp/services.d/Web_and_Scripting_Module_12_x86_64.service <my working directory>


Open your text editor and begin writing your Dockerfile. In this example, I will create a Dockerfile that will create a very simple web service with Apache and PHP 7.

FROM suse/sles12sp2
MAINTAINER "Jason Evans <jevans@suse.com>"

# The ADD command adds files from your directory into the new image
ADD *.repo /etc/zypp/repos.d/
ADD *.service /etc/zypp/services.d

RUN zypper refs && zypper refresh

RUN     zypper  --non-interactive in apache2 \
        apache2-mod_php7

ADD index.html /srv/www/htdocs/

CMD     /usr/sbin/apachectl -D FOREGROUND

EXPOSE  80


The most important thing to remember when writing a Dockerfile for SLES is this block of code:

ADD *.repo /etc/zypp/repos.d/ 
ADD *.service /etc/zypp/services.d


Without it, you are limited to writing Dockerfiles with only a limited selection of packages in the base repository.

Your First Container

With the exception of the special requirements for writing Dockerfiles, the rest of Docker for SLES works just like any other installation. In order to run a Dockerfile, simply run:

docker built -t myfirstimage:latest .


A new image is now available is now available. Using the created image from the example Dockerfile from above, you can run it as a container by doing this:

docker run -d -p 80:80 myfirstimage:latest


This will run Apache on port 80. You can find a more detailed version of my sample Dockerfile here.

Conclusion

Docker is an amazing tool. You can easily develop and run nearly any application written for any platform. In the above application, I wrote a very simple web service using SLES, but I could easily attach a container to it with a MariaDB database written for Debian and a PHP application written in OpenSUSE. All of this could be done without the system overhead of VMs and a hypervisor to control them. This is just touching the tip of the iceberg when it comes to what containers can provide.

Docker (software)

Published at DZone with permission of Jason Evans, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Automated Testing Lifecycle
  • Docker and Kubernetes Transforming Modern Deployment
  • Using Open Source for Data Integration and Automated Synchronizations
  • Mastering Node.js: The Ultimate Guide

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: