2
I’m a beginner in Docker and I’m trying to create an image with the following specifications:
- The source OS has to be the original Ubuntu 16.04. I cannot use images already available in the Docker hub;
- Must have installed apache - latest version;
- You have to have php installed and some libraries installed. It has to be php 5.5.38 (ideal) or 5.X last update or 5.6.X last update.
- You must have installed REDIS.
- REDIS, APACHE and php must be available as soon as the container is created, that is, automatically initialized.
- The system root (/var/www/html) should point to a volume /home/username/vhosts/mysite. The host is a MAC OS.
- The system has to be accessed from the host browser via mysite-dev1 or mysite-dev2 or mysite-devN ...
The ultimate goal is to create an image that will be shared among all company developers.
This is the Dockerfile that I’m wearing:
FROM ubuntu:16.04
#1
RUN apt-get update
#2
RUN apt-get install -y apache2
#3
RUN apt-get install -y php5
#4
RUN apt-get install -y redis-server
#5
RUN apt-get install -y php5-redis
COPY /home/username/vhosts/mySite /var/www/html
EXPOSE 80
Next I’m finding some errors:
Operation #3, php5 is not part of the Ubuntu 16.04 package list. From this post it is found that it needs to be updated as follows:
#6
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install php5.6
Operation #6,
I get a mistake saying that the sudo
is not recognized as a command (even if I try to run in iterative mode on the -ti terminal). Doing a search I note that the sudo
is not enabled in Ubuntu16.04 image.
If I try to run without sudo via terminal (docker run -ti ...
), I get a message saying that add-apt-repository
unseen
.
Making a other research about that mistake I find that add-apt-repository
also not available for Ubuntu 14.04 images on Docker. And by the way tbm is not available for 16.04. The proposed solution is to run:
#7
apt-get install -y software-properties-common python-software-properties
Running this operation #7 get the following error:
Doing another search, I think post which suggests modifying the apt.conf
located in /etc/apt/apt.conf
.
And this is the contents of the apt directory from inside the Ubuntu 16.04 image
.
I mean, it doesn’t have apt.conf
. Doing a search on some posts encounter that apt conf. needs to be created.
My conclusion is that I must be doing something very wrong because the goal is only to install php5.6 in Ubuntu16.04.
In conclusion, one could say some tried and tested way of creating an image with the previously listed features without going through the previous steps?
UPDATE: It seems that other images are having the same problem when trying to install php version 5.6.
A container should not have all these elements. REDIS, PHP, APACHE are 3 containers. Unlike a VM, with Docker we’re talking about PROCESS virtualization, not virtual machines, so what you’re looking for, it shouldn’t be done that way. I have prepared a wiki with this doubt, it is very recurrent | https://github.com/luizcarlosfaria/kb/wiki/FAQ-Docker-LAMP
– Luiz Carlos Faria
Luiz, I agree 100% with you. As I said, I am still beginner in Docker, but not in systems architecture. I think Docker follows the idea of microservices going further to the extreme. As you said, even sending the server to one container and php to the other. The problem is that sometimes in a company the decision is not made by one person and until everyone can understand the benefits of containers with unique functions takes a while. I liked your post. I already copied the link to my Fullstack Update group.
– zwitterion
For my question, I ended up using an official Php image of Docker Hub, already ready that already has php and apache on Linux, although it is not Ubuntu. https://hub.docker.com/_/php/
– zwitterion
the question of having several distinct processes like redis and php in the same container, there is no question as "depends" or "depending on the scenario", is categorically wrong. This type of approach is abhorred by simple Ocker architecture reasons. Docker uses kernel Features to abstract PROCESS isolation only. We’re not talking about a virtual Nvironment, we’re talking about a virtual process. And that completely changes the bias of the thing. In any OS you would have a Redis installation, another PHP installation (even if on the same machine)
– Luiz Carlos Faria
... Each element is independent, even on the same machine. The point is that Docker works like this too. The fact is that if you create an image with 2 things, such as PHP and NGINX that at first glance may even be something like that: it is wrong. PHP is php, Nginx is Nginx. Doing anything different, you will have problems with dying containers for no reason, low reuse of images and layers, overlapping responsibility. Anyway, you’re gonna have a lot of problems.
– Luiz Carlos Faria
Understood and I agree with you Luiz. As I work more with Docker I understand his ideology. My next version will no longer have REDIS docked in the container.
– zwitterion