Most of these commands use image id, image name, and the container id depend on the requirement. Docker daemon always run as the root user. Docker has a concept of "base containers", which you use to build your containers. After making changes to a base container, you can save those change and commit them.
One of Docker's most basic images is called "Ubuntu" (which I have used in my sample described in this post)
A Dockerfile provides a set of instructions for Docker to run on a container.
For each line in the Dockerfile, a new container is produced if that line results in a change to the image used. You can create you own images and commit them to Docker Hub so that you can share them with others. The Docker Hub is a public registry maintained by Docker, Inc. that contains images you can download and use to build containers.
With this blog post, I am creating a docker image to start wso2 ESB server. I have created the dockerfile below to create my image.
FROM ubuntu:14.04
MAINTAINER Nipuni nipuni@wso2.com
RUN apt-get update
RUN sudo apt-get install zip unzip
COPY wso2esb-4.8.1.zip /opt
COPY jdk1.8.0_60.zip /opt
WORKDIR "/opt"
RUN unzip jdk1.8.0_60.zip
RUN unzip /opt/wso2esb-4.8.1.zip
ENV JAVA_HOME /opt/jdk1.8.0_60
RUN chmod +x /opt/wso2esb-4.8.1/bin/wso2server.sh
EXPOSE 9443 9763 8243 8280
CMD ["/opt/wso2esb-4.8.1/bin/wso2server.sh"]
FROM ------------>will tell Docker what image is to base this off of.
RUN ------------->will run the given command (as user "root") using sh -c "your-given-command"
ADD ------------->will copy a file from the host machine into the container
WORKDIR ------ >set your location from which you need to run your commands from
EXPOSE ---------->will expose a port to the host machine. You can expose multiple ports.
CMD -------------- >will run a command (not using sh -c). This is usually your long-running process. In this case, we are running the wso2server.sh script.
Following are the possible errors that you may face while building the docker image with a dockerfile:
Step 1 : FROM ubuntu:14.04
---> 1d073211c498
Step 2 : MAINTAINER Nipuni nipuni@wso2.com
---> Using cache
---> c368e39cc306
Step 3 : RUN unzip wso2esb-4.8.1.zip
---> Running in ade0ad7d1885
/bin/sh: 1: unzip: not found
As you can see the dockerfile has encountered an issue in step 3 which is “unzip is not found” to run as a program. This is because we need to add all the dependencies to the dockerfile before using them. Dockerfile creates an image based on the basic image “ubuntu:14.04” which is just a simple Ubuntu image. You need to install all the required dependencies (in my case it would be unzip) before using them.
Step 5 : RUN unzip wso2esb-4.8.1.zip
---> Running in e8433183014c
unzip : cannot find or open wso2esb-4.8.1.zip, wso2esb-4.8.1.zip.zip or wso2esb-4.8.1.zip.ZIP
The issue is docker cannot find the zip file. I have added my zip file as the same location of my dockerfile. While building the docker image, you need to copy your resources to docker instance location with “COPY” command.
Step 9 : RUN /opt/wso2esb-4.8.1/bin/wso2server.sh
Error: JAVA_HOME is not defined correctly.
CARBON cannot execute java
We need JAVA_HOME environment variable to be set properly while running wso2 products. Docker support setting environment variables with “ENV” command. You can copy your jdk zip file similar to wso2esb-4.8.1.zip and set JAVA_HOME. I have added below commands to my dockerfile.
COPY jdk1.7.0_65.zip /opt
RUN unzip jdk1.7.0_65.zip
ENV JAVA_HOME /opt/jdk1.7.0_65
After successfully creating the dockerfile, save it with name "Dockerfile" in you preferred location. Add wso2esb-4.8.1.zip and jdk1.7.0_65.zip to same location.
You can then run the saved dockerfile with command below:
sudo docker build -t wso2-esb .
As result you can see the commands listed in the dockerfile are running one by one with final line "Successfully built <image-ID>".
You can view the newly created image with "sudo docker images".
You can then run your image with command "sudo docker run -t <Image-ID>". You should be able to see the logs while starting the wso2 server.
You also can access the server logs with "sudo docker logs <container-ID>".
No comments:
Post a Comment