On this article, will see how to build docker images from dockerfile, for example i will create docker images who run pxc-57 with timezone Asia/Jakata

Steps :

create directory for place of dockerfile

# mkdir mydocker_build

change to dir mydocker_build and create new file with name Dockerfile

# cd mydocker_build
# vi Dockerfile

Content of dockerfile :

FROM debian:8.5
LABEL maintainer "erick_s"
RUN apt-get update
RUN apt-get install -y wget vim locales net-tools
RUN locale-gen en_US.UTF-8
RUN localedef -i en_US -f UTF-8 en_US.UTF-8
ENV DEBIAN_FRONTEND noninteractive
RUN wget https://repo.percona.com/apt/percona-release_0.1-4.jessie_all.deb
RUN dpkg -i percona-release_0.1-4.jessie_all.deb
RUN apt-get update
RUN apt-get install -y percona-xtrabackup-24 percona-xtradb-cluster-57 percona-xtradb-cluster-client-5.7 percona-xtradb-cluster-common-5.7 percona-xtradb-cluster-server-5.7 psmisc rsync socat tcpd libperconaserverclient20-dev 
RUN apt-get install -y python-mysqldb
RUN apt-get autoclean
RUN service mysql stop
RUN rm -rf /var/lib/apt/lists/*
RUN rm -rf /var/lib/mysql/*
RUN mv /etc/mysql/my.cnf /var/lib/mysql/my.cnf.old
RUN echo Asia/Jakarta > /etc/timezone
RUN ln -sf /usr/share/zoneinfo/Asia/Jakarta /etc/localtime
RUN dpkg-reconfigure -f noninteractive tzdata
CMD ["/bin/bash"]

Next run docker build to building docker images

# docker build -t debian .

after all process finish, you can see new docker images. run docker images to see it on the top

# docker images 

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
debian              latest              4d2ba797cc5b        10 seconds ago      614.4 MB

Commit docker images

To commit your new docker images, run your docker images for something like this

# docker run -itd --name=mysql-57 --hostname=dbnode 4d2ba797cc5b /bin/bash
e33b0de986d442018f509e3f458cc1467c02840a66a2277d1e04881fe4b7d633

Show active container

# docker ps -a

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                   PORTS               NAMES
e33b0de986d4        4d2ba797cc5b        "/bin/bash"         2 minutes ago       Up 2 minutes                                 mysql-57

Lets to commit you docker images

# docker commit e33b0de986d4 zsdiary/percona57 
# docker images

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
zsdiary/percona57   latest              2ca746b405bb        19 seconds ago      614.4 MB

Tag your docker images

# docker tag 2ca746b405bb zsdiary/percona57:5.7

Show your docker images to see changes

# docker images

REPOSITORY          TAG                 IMAGE ID            CREATED              SIZE
zsdiary/percona57   5.7                 2ca746b405bb        About a minute ago   614.4 MB
zsdiary/percona57   latest              2ca746b405bb        About a minute ago   614.4 MB

Yey… docker images is ready to use

Push your docker images to dockerhub

If you want to save your docker images, docker have place for it. you can use dockerhub to push your docker images, for example i will push my docker images to my dockerhub, before it you must login and create repository on dockerhub

# docker login --username=ericks --email=erick.1383@gmail.com

Push the docker images

# docker push zsdiary/percona57:5.7

Finish, hope this article will help you

Thank you

Advertisements