From Centos Dockerfile


Dockerfile Example (Centos ) Mentioned below is a Dockerfile example that we have already created, for CentOS with a webserver (apache) installed on it. MAINTAINER linuxtechlab. LABEL Remarks='This is a dockerfile example for Centos system'. RUN yum -y update &&. The Dockerfile is a YAML file, which is a text file with some syntax: relations are expressed using indentation (spaces) and each line is comprised of key and value pairs. Let’s start with a simple Dockerfile that installs package props (contains commands htop and ps ) to a Debian image. The FROM instruction needs to be the first instruction in your Dockerfile, as it is the environment all subsequent instructions will be ran in. Add the following to the beginning of your Dockerfile to use the official CentOS 7 image from the Docker Hub. FROM centos:7 RUN. The RUN instruction will run a command in your image environment. The following is the steps for building CentOS docker image using the file with the name of ‘Dockerfile’. Just create a file with the name of ‘Dockerfile’. Just place it in any location. The content of that file is available as follows: #Getting base image from CentOS FROM centos:7 MAINTAINER maintainername LABEL Remarks. Dockerfile Linux Projects (150) Dockerfile Aws Projects (148) Dockerfile Docker Image Alpine Projects (147) Java Docker Dockerfile Projects (145).

  1. From Centos Dockerfile To Access
  2. From Centos Dockerfile Download
  3. From Centos Dockerfile To Yahoo
  4. From Centos Dockerfile

The problem

Setting up a new computer is always long and difficult. From time to time, a new developer joins the team and must setup their computer to build the code from the team’s repository. This can be a long and frustrating exercise. This is even more difficult when the code is cross-platform and has to be built under Linux and Windows.

In this post, I will show how to transform a dockerfile into a WSL distribution in an automated fashion. This allows the Windows developer to build and test the code on Linux using the same build environment as the CI system.

From Centos Dockerfile

Leveraging the existing tools

Windows users can leverage a technology called Windows Subsystem for Linux to easily switch between Windows and Linux tools. It is possible to run multiple Linux distributions simultaneously, making it great for cross-platform development.

Setting up the Linux distribution remains just as difficult as setting up a new Linux computer.

To ease the task, you can use Docker tools to describe the configuration of the distribution in a dockerfile. This dockerfile details each library to install, all the tools to download and extract, as well as the necessary environment variables.

From centos dockerfile to excel

Usually, this container image is used by the CI system to build the code on every commit.

Overview of the procedure

Let’s assume that the team already has Docker images used by the CI system to build the code. The procedure is (almost) as simple as:

  1. Build the Docker image from the Dockerfile.
  2. Run the newly created image in a container.
  3. Export the container filesystem using the ‘docker export’ command.
  4. Import the filesystem in WSL using the ‘wsl –import’ command.

Of course, if it was that easy, I wouldn’t be writing a post about it, right? Some of the issues with this procedure include:

  • Environment variables defined in the Dockerfile are lost
  • If the CI system is running in an AWS EC2 instance, the AWS profile/credentials are lost
  • The export and import are done on different computers in real life.

So let’s take a closer look at each issue and how to solve them.

Environment Variables

The environment variables are not saved in the filesystem by Docker. They are in the image metadata and applied at runtime, but only in-memory. To retrieve them, the docker inspect command is used, along with some golang goodness to format the output.

  1. Create a file containing the export definition of the variables
  2. Get the current global profile
  3. Update the global profile

AWS credentials

Our goal is to re-use the AWS credentials of the Windows user inside of the WSL distribution.

On an EC2 instance using an instance profile, the AWS command-line tools hit a local URI to determine the access keys to use. But for a developer, they will usually have their own configuration files in their home folder.


It is thus necessary to link the Windows home folder to the Linux home folder and share the AWS_PROFILE environment variable. In Powershell, this looks like:

Exporting and importing

The easy part! On the CI server, the tarball is simply gzipped then uploaded to an S3 bucket. On Windows, the tar.gz file is directly imported.

Wrapping up

We have shown how to take a typical Dockerfile used on the CI server, and transform it into a fully functional WSL distribution. The Windows developers can then compile and test on their computer Windows and Linux binaries, without spending the whole day (or week!) trying to setup their computer. This time-saving trick becomes extremely useful to give your team an efficiency boost as it continues to grow.

The recommended way to create images for sharing is from a docker file. A docker file is essentially a script which can recreate the building of your image. We will go over how to create one for nginx on CentOS in this tutorial.

Creating the docker file.

It is recommended that each docker file is contained in a separate directory. This will help keep everything organized and give you a place to store any extra files if needed.

  1. Create a new directory for your docker build file.
  2. Create the docker file

Dockerfile format

The dockerfile format is fairly straightforward. Each line has an instruction and argument. You can read more about instructions and arguments in the dockerfile reference documentation

In this tutorial we will be using the following instructions:

From Centos Dockerfile To Access


The FROM instruction specifies the base image to use as a foundation to our new image. In our example, we will be using the official CentOS image from our previous tutorials. The FROM instruction needs to be the first instruction in your Dockerfile, as it is the environment all subsequent instructions will be ran in.

  • Add the following to the beginning of your Dockerfile to use the official CentOS 7 image from the Docker Hub.


The RUN instruction will run a command in your image environment. By default, any arguments will be ran in shell. Each argument is technically passing the following command to the environment.

  • We need to run the necessary commands to install nginx on our CentOS environment. This will include:
    • Installing epel-release
    • Updating to notify yum of the new repository
    • Installing nginx.
  • Add the following to your Dockerfile on the line after the FROM instruction:

From Centos Dockerfile Download


The ADD instruction copies files to the image’s file system. This is useful for adding configuration files, scripts, or any other files needed in your environment. We will create a sample html file to add to the nginx root directory.

  • First we will need to create a basic html file in our Dockerfile directory.
    • This will create a file called html, and show look like this:
  • Add the following to your Dockerfile on the line after the last RUN instruction:


The EXPOSE instruction tells docker which network ports the container will listen on. We are setting up an http server, so we will need to have the container listen on port 80/tcp.

  • Add the following to your Dockerfile on the line after the ADD instruction:


Finally, we need to tell docker what command to run when the container is started up with the CMD instruction. The argument for this instruction will differ depending on what application you want your container to run. In this example, we will start nginx in non-daemon mode, so that when we attach to the running container, we will see the nginx console.

  • The CMD syntax is as follows:
  • Add the following to your Dockerfile after the EXPOSE instruction:

Finished Dockerfile

When you are finished, your docker file should look something like this.

Building the Image

Now that we have a docker file and any needed files in our directory, it is time to build the image. From within the docker file directory, execute the following:

  • This will run each instruction in your docker file sequentially, and create a local docker image called dopensource/nginx.
    • You will see each instruction executed in your console, which is very helpful for debugging any issues with your build file.
  • Here is what the end of my build process looks like.

Running your new image.

From Centos Dockerfile To Yahoo

Now that you have built your image, it is time to run the image as a new docker container. Remember, we will need to expose port 80 in our run command and specify which port on the host to bind to.

From Centos Dockerfile

  • This will run our new image, and bind the container’s port 80 to our host’s port 8081.
    • Browse to your docker hosts ip adress, specifying port 8081. You should see the basic html header we created prior.



  • Most Viewed News

    • Mac Office 365
    • Install Macos On Linux
    • Idm Osx
    • Install Font Photoshop Mac