1

Yesterday I've been asked about how to make a docker images with dockerfile

This time I want to add a question

If I want to make the OS ubuntu 14:04 on images docker, which it is installed, postgresql-9.3.10, install Java JDK 6, copy the file (significant location), and create a user on the images.

Whether I can combine of several dockerfile as needed for images? (dockerfile of postgresql, java, copyfile, and create a user so one dockerfile)

Example. I made one dockerfile "ubuntu" which contains the command

top line

# Create dockerfile # get OS ubuntu to images FROM ubuntu: 14:04 # !!further adding a command on the following link, below the line per-dockerfile(intends command in dockerfile on the link) # command on dockerfile postgresql-9.3 https://github.com/docker-library/postgres/blob/ed23320582f4ec5b0e5e35c99d98966dacbc6ed8/9.3/Dockerfile # command on dockerfile java https://github.com/docker-library/java/blob/master/openjdk-6-jdk/Dockerfile # create a user on images ubuntu RUN adduser myuser # copy file/directory on images ubuntu COPY /home/myuser/test /home/userimagedockerubuntu/test # ? CMD ["ubuntu:14.04"] 

Please help me

3 Answers 3

2

No, you cannot combine multiple Dockerfile.

The best practice is to:

  • start from an imabe already included what you need, like this postgresql image already based on ubuntu.
    That means that if your Dockerfile starts with:

    FROM orchardup/postgresql 

You would be building an image which already contains ubuntu and postgresql.

  • COPY or RUN what you need in your dockerfile, like for openjdk6:

    RUN \ apt-get update && \ apt-get install -y openjdk-6-jdk && \ rm -rf /var/lib/apt/lists/* ENV JAVA_HOME /usr/lib/jvm/java-6-openjdk-amd64 

Finally, your default command should run the service you want:

# Set the default command to run when starting the container CMD ["/usr/lib/postgresql/9.3/bin/postgres", "-D", "/var/lib/postgresql/9.3/main", "-c", "config_file=/etc/postgresql/9.3/main/postgresql.conf"] 

But since the Dockerfile of orchardup/postgresql already contains a CMD, you don't even have to specify one: you will inherit from the CMD defined in your base image.

Sign up to request clarification or add additional context in comments.

5 Comments

kalau untuk OS Ubuntu nya perlu menambahkan syntax CMD di line terakhir yang menunjukkan [/bin/bash] ? ` CMD [/bin/bash] `
@YudiDwiyanto You don't need CMD [/bin/bash]: by default that postgres image will run postgres. If you want to run that image by opening a bash instead, then you do a <span class="notranslate">docker run -it --rm myPostgres bash</span>: the last parameter will override the CMD command defined in your image by default.
@YudiDwiyanto apakah Anda menerima, maka unaccept jawaban ini ? Apa yang hilang?
Ketika ingin menginstall java jdk 6, masih terjadi error
Ternyata, waktu "apt-get install -y openjdk-6-jdk && \" saya kurang menambahkan -y ketika mau install, oke fix accept.. Thanks, sir
2

I think nesting multiple Dockerfiles is not possible due to the layer system. You may however outsource tasks into shell scripts and run those in your Dockerfile.

In your Dockerfile please fix the base image:

FROM ubuntu:14.04

Further your CMD is invalid. You may want to execute a bash with CMD ["bash"] that you can work with.

Comments

1

I would suggest you to start with the doc on Dockerfile as you clearly missed this and it contains all the answers to your questions, and even questions you don't even think to ask yet.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.