How to Interactively Create a Docker Container
来源:互联网 发布:虚拟充值软件 编辑:程序博客网 时间:2024/06/04 18:50
http://linoxide.com/linux-how-to/interactively-create-docker-container/
Hi everyone, today we'll learn how we can interactively create a docker container using a docker image. Once we start a process in Docker from an Image, Docker fetches the image and its Parent Image, and repeats the process until it reaches the Base Image. Then the Union File System adds a read-write layer on top. That read-write layer, the information about its Parent Image and some other information like its unique id, networking configuration, and resource limits is called aContainer. Containers has states as they can change from running to exited state. A container with state asrunning includes a tree of processes running on the CPU, isolated from the other processes running on the host where asexited is the state of the file system and its exit value is preserved. You can start, stop, and restart a container with it.
Docker Technology has brought a remarkable change in the field of IT enabling cloud service for sharing applications and automating workflows, enabling apps to be quickly assembled from components and eliminates the friction between development, QA, and production environments. In this article, we'll build CentOS Instance in which we'll host a website running under Apache Web Server.
Here is quick and easy tutorial on how we can create a container in an interactive method using an interactive shell.
1. Running a Docker Instance
Docker initially tries to fetch and run the required image locally and if its not found in local host the it pulls from theDocker Public Registry Hub . Here. we'll fetch and create a fedora instance in a Docker Container and attach a bash shell to the tty.
# docker run -i -t fedora bash
2. Installing Apache Web Server
Now, after our Fedora base image with instance is ready, we'll now gonna install Apache Web Server interactively without creating a Dockerfile for it. To do so, we'll need to run the following commands in a terminal or shell.
# yum update
# yum install httpd
# exit
3. Saving the Image
Now, we'll gonna save the changes we made into the Fedora Instance. To do that, we'll first gonna need to know the Container ID of the Instance. To get that we'll need to run the following command.
# docker ps -a
Then, we'll save the changes as a new image by running the below command.
# docker commit aefcdd0669ad fedora-httpd
Here, the changes are saved using the Container ID and image name fedora-httpd. To make sure that the new image is running or not, we'll run the following command.
# docker images
4. Adding the Contents to the new image
As we have our new Fedora Apache image running successfully, now we'll want to add the web contents which includes our website to Apache Web Server so that our website will run successfully out of the box. To do so, we'll need to create a new Dockerfile which will handle the operation from copying web contents to allowing port 80. To do so, we'll need to create a file Dockerfile using our favorite text editor as shown below.
# nano Dockerfile
Now, we'll need to add the following lines into that file.
FROM fedora-httpd
ADD mysite.tar /tmp/
RUN mv /tmp/mysite/* /var/www/html
EXPOSE 80
ENTRYPOINT [ "/usr/sbin/httpd" ]
CMD [ "-D", "FOREGROUND" ]
Here, in above Dockerfile, the web content which we have in mysite.tar will get automatically extracted to /tmp/ folder. Then, the entire site will move to the Apache Web root ie /var/www/html/ and the expose 80 will open port 80 so that the website will be available normally. Then, the entrypoint is set to /usr/sbin/httpd so that the Apache Server will execute.
5. Building and running a Container
Now, we'll build our Container using the Dockerfile we just created in order to add our website on it. To do so, we'll need to run the following command.
# docker build -rm -t mysite .
After building our new container, we'll want to run the container using the command below.
# docker run -d -P mysite
Conclusion
Finally, we've successfully built a Docker Container interactively. In this method, we build our containers and image directly via interactive shell commands. This method is quite easy and quick to build and deploy our images and containers. If you have any questions, suggestions, feedback please write them in the comment box below so that we can improve or update our contents. Thank you ! Enjoy :-)
You might also like
- How to Interactively Create a Docker Container
- How to Get Code into a Docker Container
- Docker - How to Connect to a MySQL Running Container Using MySQL Command Line Client
- symbian 符合控件 滚动条How to Create a Scrollable Container
- Docker - How to create a custom database from docker mysql image
- How to Create a Customer
- how to create a Makefile
- (全英文)How to install and run a simple Asp.Net 5 Application in a Docker Container
- How to upgrade docker container after its image changed
- How to Create a REST Protocol
- How to create a user in PostgreSQL
- How to create a javascript class~
- How to create a test plan?
- how to create a sln file
- How to: Create a Numeric Text Box
- How to create a minimal master page
- How to create/display a modal window?
- How to create a new routine
- spring-security 在jsp中的标签库
- FPGA视觉从入门到放弃——小波矩与支持向量机刷MNIST
- SparkR环境搭建
- scala隐式参数(implicit)
- 7-1什么是对象 Date
- How to Interactively Create a Docker Container
- LibUSB-Win32
- Spring AOP 实现写事件日志功能
- iOS 基础篇12- 定时器的使用
- linux脚本 运行java程序引入jar
- spark内核揭秘-spark任务调度系统
- 创建一个上线web需要的思考问题(一)
- libusb的使用教程和例子
- 液压阀工作原理及动画