Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How Docker uses Dockerfile to create Container Images

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article focuses on "how Docker uses Dockerfile to create container images". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how Docker uses Dockerfile to create container images".

Original link: Docker uses Dockerfile to create container images that support ssh service self-startup

1. First create a Dockerfile file with the following contents

# Select an existing os image as the author of the basic FROM centos:centos6 # image MAINTAINER Fanbin Kong "kongxx@hotmail.com" # install the openssh-server and sudo packages And set the UsePAM parameter of sshd to no RUN yum install-y openssh-server sudo RUN sed-I 's/UsePAM yes/UsePAM no/g' / etc/ssh/sshd_config # to add the test user admin, password admin And add this user to sudoers RUN useradd admin RUN echo "admin:admin" | chpasswd RUN echo "admin ALL= (ALL) ALL" > > / etc/sudoers # the following two sentences are special and must be on centos6. Otherwise, the created container sshd cannot log in to RUN ssh-keygen-t dsa-f / etc/ssh/ssh_host_dsa_key RUN ssh-keygen-t rsa-f / etc/ssh/ssh_host_rsa_key # to start the sshd service and expose port 22 RUN mkdir / var/run/sshd EXPOSE 22 CMD ["/ usr/sbin/sshd", "- D"]

Dockerfile files have their own syntax and commands, which can be found in the official documentation of Docker.

two。 Once you have the Dockerfile file, you can create the image file according to Dockerfile. In the directory where Dockerfile is located, run the following command

Sudo docker build-t centos6-ssh.

When the command is successful, an image named centos6-ssh is created, which can be viewed using "sudo docker images".

3. At this point, you can create your own container based on the image file created above. The following command creates a container named "mytest".

Sudo docker run-d-P-- name=mytest centos6-ssh

4. With the container, we can test our ssh service.

4.1 run "sudo docker inspect mytest" to see the IP address of the current startup container, and then run the following command to test

Ssh admin@

4.2 alternatively, it can be accessed through the port mapping of docker. Use "sudo docker port mytest 22" to view the port of the host machine corresponding to port 22 of the current container, and then access it with the following command

Ssh admin@-p

At this point, I believe you have a deeper understanding of "how Docker uses Dockerfile to create container images". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report