Our containers are daemons processes running in the Background.If for some reason we stop them or our host shutdown all the data running in that container can get lost. We can prevent that creating a new image for our running container.First we need to obtain our container ID. docker ps CONTAINER ID 8a6e56dbd8b3 Now we can create a Snapshot, the name format is important if we want to push our customize image in the Docker Hub repository.
Read more →
In this example we are going to ‘attach’ some volumes to a container. The volume is created in our filesystem and can interact with our running container, this is important if we don’t want to lose our data when we stop the running container. mkdir mydata echo "host data" > mydata.txt The next step is create a local volume and attached to centos:latest container in interactive mode. docker run -i -t --name='local_vol' -v /home/usr/mydata:/mydata centos:latest /bin/bash Now we can verify that the remote host volume is mounted in our container ‘df -h’ and the text file created appears in the folder.
We use a Dockerfile to build a Docker Image, we can write specific instructions such a install a package, update the system and define the ports that the container will be listen. In the following example we write a Dockerfile in the /root directory ## Dockerfile that modifies centos:latest FROM centos:latest MAINTAINER User Name <firstname.lastname@example.org> ## Update the server OS RUN yum -y upgrade ## Install Apache Web Server RUN yum -y install httpd ## Install OpenSSH-Server RUN yum -y install openssh-server ## Expose the SSH and Web Ports for attachment EXPOSE 22 80 Now we execute the build command docker build -t mycustomimg/withservices:v1 /root Once the image is build we verify that the image is in our list.
Read more →