Add Image to my Base Docker Image - php

I have a docker base image that runs CentOS 6.5. This image is saved on my computer. I could not find anything that talks about how to add more images into this base image. So for example I have this base image of CentOS6.5, I need too add postgresql 9.3, and php too this base image. Is there a way once you already have a base image made, to add more packages too that base image?

That's the whole purpose of the Docker file : build something on top of an image.
Create your dockerfile
Build the new image and tag it with docker build -t <tag> <path/to/build/context>
Then if you want to share it, push it to your private registry or to the docker hub to make it world accessible (docker push <tag>).
The build context of step 2 is the parent directory of your Dockerfile. For instance if you run the command in the directory where your dockerfile is it would be docker build -t <tag> ..

You can use Dockerfiles and docker build to do this e.g.:
FROM yourCentos
MAINTAINER your name
RUN yum install ...
CMD ...
And then docker build -t="myImage" . in the direcotry where you created the dockerfile.
Or you can upgrade youe images via CLI (not the preferd way!!) and commit them.

Related

Link Docker Container to Volumes

I currently have a codebase for Drupal using Drupal-VM vagrant box and VirtualBox. I would like to migrate to docker but I am unaware on how to integrate it with my existing code base.
Can anyone help me? I have followed instructions from Docker Hub - Drupal Install Steps and MySQL and Drupal Container to spin up mysql and Drupal images but how do I make it point to my pre-existing codebase?
Previous posts with more Details, Questions and Background:
Migrate Drupal Local Environment to Docker/Container
Drupal Local Development Setup/Environment
after spinning up the docker container you can copy the existing code to the container using docker cp docker cp docs
as far as the database you can just import it to the mysql container
to link the container to a volume use the -v flag when starting the container

docker-php-ext-install running every build making new images and leaving <none>

My dockerfile looks like this:
FROM php:7.3.3-apache
COPY src/ /var/www/html
RUN docker-php-ext-install mysqli
EXPOSE 80
Every time I run the following command docker will build a new image, download the mysqli package again and leaves a : images, when I am just simply changing a line in the php file.
docker build -t php-server .
Is there a way to make docker not re download the package and just update the image that already exists?

How can I add helper scripts docker-php-ext-configure, docker-php-ext-install in my docker image

I got detail about some helper scripts but I do not know how to add the support of these scripts in docker file. When I try to use the scripts
Scripts like: docker-php-ext-configure, docker-php-ext-install, and docker-php-ext-enable to more easily install PHP extensions.
I am getting errors like: /bin/sh: 1: docker-php-ext-configure: not found
I am using
FROM debian:stretch
for build docker container in my docker file.
Same helper scripts are working perfectly fine inn different images like:
FROM php:7.1-apache
FROM php:7.2-apache
If we build Docker file with these images.
php:7.X-apache image is already pre-built with all those scripts included as can be seen here: https://github.com/docker-library/php/tree/master/7.2/stretch/apache
If you need PHP 7.1 image/files you can try to search repository for last version of 7.1 image before it was deprecated.
All of those scripts can be found in this repo:
https://github.com/docker-library/php
Just RUN the scripts within your project directory via Dockerfile, or COPY over to the /usr/bin folder then RUN as you would any other bin script. Just keep in mind those scripts assume an Alpine-esque directory structure so if you're using something like Debian/Ubuntu it may not work out of the box.

How to force new wordpress docker image?

How do I force docker-compose to update an image?
Given the recent exploits of php (e.g. MS-ISAC ADVISORY NUMBER: 2018-101), I want to update my docker-compose wordpress.
I tried:
docker-compose down && docker-compose build --pull && docker-compose up -d
When I check the version of php though, it lists 7.2.9 rather than 7.2.10
I check it by:
docker exec -it wordpress_wordpress_1 /bin/bash
php -v
I believe that it should list 7.2.10 because when i go to wordpress on docker hub and follow the link for latest, I see that it lists php:7.2-apache, and when I check php on docker hub for 7.2-apache, the Dockerfile lists 7.2.10 (see: L116)
It depends on whether the wordpress image available in docker hub was rebuilt since php was updated.
Your best bet is to rebuild the wordpress image yourself, instead of pulling it from wordpress using wordpress' dockerfile.
Instead of using latest, use the latest tag released. That would force compose to use that version of the image. Or you could also use the --no-cache flag when running docker-compose build to download the image again.
It turns out that even though the changes were merged, dockerhub was still showing that the most recent update was before the merge. (so dockerhub wasn't up to date yet)
https://github.com/docker-library/php#see-a-change-merged-here-that-doesnt-show-up-on-docker-hub-yet

How to publish an Artifact from inside a Docker container

I'm running a TeamCity agent that spawns a docker container, running several tasks inside that (php) container. Such as phpunit, phplint and composer. I zipped the content inside the container if all tests pass, it will create a phpproject.zip.
After it's done I would like to push that phpproject.zip as an Artifact back to the TeamCity server from inside the docker container.
My docker container is running with the --rm parameters to remove the container after the script is done.
Is this possible?
Tim
You can map a volume of the Docker daemon to the container with the -v parameter and publish the artifacts to the daemon:
...
# Your build path and build command here
VOLUME /foo/build
ENTRYPOINT make
In TeamCity, configure a Docker build step to build the Dockerfile, and name:tag the resulting image. Add a second step in which you configure an other... Docker command as run, with the arguments:
-v /tmp/build:/foo/build --rm <name of image>
The result is then available in /tmp/build on the agent, and you can configure that as artifact path in the project's settings, or alternatively echo "##teamcity[publishArtifacts '/tmp/build']" somewhere.

Categories