How to restart phpmyadmin on my downloaded docker image - docker

I pulled the phpmyadmin docker image from hub.docker.com.
I need to make some changes to the config.sample.inc.php. However, I don't know how to restart phpmyadmin so my changes will be picked up.
I ran
ps -ef | grep apache
on the container and saw a bunch of
apache2 -DFOREGROUND
processes running but again, I don't know how to restart this. Can someone tell me how to restart phpmyadmin from the docker image from hub.docker.com?
# ps -ef | grep apache
root 1 0 0 00:33 ? 00:00:00 apache2 -DFOREGROUND
www-data 17 1 0 00:33 ? 00:00:00 apache2 -DFOREGROUND
www-data 18 1 0 00:33 ? 00:00:00 apache2 -DFOREGROUND
www-data 19 1 0 00:33 ? 00:00:00 apache2 -DFOREGROUND
www-data 20 1 0 00:33 ? 00:00:00 apache2 -DFOREGROUND
www-data 21 1 0 00:33 ? 00:00:00 apache2 -DFOREGROUND
root 36 22 0 00:45 pts/0 00:00:00 grep apache
root#e24b3b0f5cd5:/var/www/html#

Try by removing each image and container using docker system prune --all (and then 'y'). By the way, you can set up volumes over the folder where there are the files that you want to update: updating files in the folder explicited in the volumes, you will have the updates in runtime

Related

Using the same Docker image file permissions differ from machine to machine

I have a problem, that I cannot grasp at all. I'm running my Jenkins pipeline in a Docker container on the master node. Now I added another node and want to run the pipeline there as well.
However, using the same image I get different file permissions in the container:
### master
> docker image ls node:10.20.1-stretch
REPOSITORY TAG IMAGE ID CREATED SIZE
node 10.20.1-stretch c5f1efe092a0 13 days ago 912MB
> docker run --rm -ti -u 1000:1000 node:10.20.1-stretch ls -la /home/node
total 20
drwxr-xr-x 2 1000 1000 4096 May 15 20:31 .
drwxr-xr-x 3 0 0 4096 May 15 20:31 ..
-rw-r--r-- 1 1000 1000 220 May 15 2017 .bash_logout
-rw-r--r-- 1 1000 1000 3526 May 15 2017 .bashrc
-rw-r--r-- 1 1000 1000 675 May 15 2017 .profile
### node 1
> docker image ls node:10.20.1-stretch
REPOSITORY TAG IMAGE ID CREATED SIZE
node 10.20.1-stretch c5f1efe092a0 13 days ago 912MB
> docker run --rm -ti -u 1000:1000 node:10.20.1-stretch ls -la /home/node
total 20
drwxr-xr-x 2 0 0 4096 May 26 05:42 .
drwxr-xr-x 1 0 0 4096 May 26 05:42 ..
-rw-r--r-- 1 0 0 220 May 26 05:42 .bash_logout
-rw-r--r-- 1 0 0 3526 May 26 05:42 .bashrc
-rw-r--r-- 1 0 0 675 May 26 05:42 .profile
I observed a similar behavior for the /tmp directory, which has chmod 1777 on master and 1755 on node 1.
# master
> docker -v
Docker version 19.03.9, build 9d988398e7
> dockerd -v
Docker version 19.03.9, build 9d988398e7
# node 1
> docker -v
Docker version 19.03.10, build 9424aeaee9
> dockerd -v
Docker version 19.03.10, build 9424aeaee9
I assume the wrong behavior is on node 1, as the /home/node directory and all of its children are owned by root:root there, but the same directory is owned by node:node on the master. However, I already upgraded the Docker version on node 1 from 19.03.8 to 19.03.10 and nothing changed.
It there anything I don't understand about Docker containers? I have been working with them for a while, but never observed such a behavior.
I have change the storage driver from overlay2 to aufs. Now I have the correct permissions.

Docker: opposite of docker import

An image created with docker import fails to run, because a necessary file is missing.
I am attempting to debug what is in the image and what is missing.
What I have tried
docker save creates a tarball, but it is not a simple tarball with files but all kind of metadata
docker export requires a running container.
Do I have any other alternatives?
If the image has a working shell, use that to debug.
docker run -ti BROKEN_IMAGE sh
If a shell doesn't work, export the image contents and you will have a tar file you can extract somewhere and inspect.
CID=$(docker create BROKEN_IMAGE)
docker export $CID | tar -tvf -
Detail
The source file/data for a docker import should be a tar file of the plan image contents. This data can be viewed or extracted somewhere with the tar command:
$ CID=$(docker create busybox)
$ docker export $CID > myimage.tar
$ tar -tvf myimage.tar
-rwxr-xr-x 0 0 0 0 28 Nov 01:03 .dockerenv
drwxr-xr-x 0 0 0 0 1 Nov 22:58 bin/
-rwxr-xr-x 0 0 0 1049688 1 Nov 22:58 bin/[
-rwxr-xr-x 0 0 0 0 1 Nov 22:58 bin/[[ link to bin/[
-rwxr-xr-x 0 0 0 0 1 Nov 22:58 bin/acpid link to bin/[
...
If the file/data is from a docker save there are additional layers to cater for the image metadata and layers.
$ docker save busybox | tar -tvf -
drwxr-xr-x 0 0 0 0 3 Nov 22:39 036a82c6d65f2fa43a13599661490be3fca1c3d6790814668d4e8c0213153b12/
-rw-r--r-- 0 0 0 3 3 Nov 22:39 036a82c6d65f2fa43a13599661490be3fca1c3d6790814668d4e8c0213153b12/VERSION
-rw-r--r-- 0 0 0 1174 3 Nov 22:39 036a82c6d65f2fa43a13599661490be3fca1c3d6790814668d4e8c0213153b12/json
-rw-r--r-- 0 0 0 1337856 3 Nov 22:39 036a82c6d65f2fa43a13599661490be3fca1c3d6790814668d4e8c0213153b12/layer.tar
-rw-r--r-- 0 0 0 1497 3 Nov 22:39 6ad733544a6317992a6fac4eb19fe1df577d4dec7529efec28a5bd0edad0fd30.json
-rw-r--r-- 0 0 0 203 1 Jan 1970 manifest.json
-rw-r--r-- 0 0 0 90 1 Jan 1970 repositories
The LAYER_ID/layer.tar file(s) contain each layer contents which would need to be extracted in the order of the Layers array in manifest.json.
$ cat manifest.json | jq
[
{
"Config": "6ad733544a6317992a6fac4eb19fe1df577d4dec7529efec28a5bd0edad0fd30.json",
"RepoTags": [
"busybox:latest"
],
"Layers": [
"036a82c6d65f2fa43a13599661490be3fca1c3d6790814668d4e8c0213153b12/layer.tar"
]
}
]
Docker doesn't need a running container to be able to run docker export, it just needs a container:
docker create --name toexport brokenimage
docker export toexport -o exported.tar
docker rm toexport
The docker save is complimentary with the docker load command and can be used to save an image in a suitable format for importing, preserving each image layer and image metadata. This is why the resulting tarball has more tarballs inside it.

Xvfb command in docker supervisor conf not working

I have a Docker image based on Ubuntu that runs a supervisor script as the CMD at the end of the Dockerfile. This successfully runs uwsgi and nginx in the container on start up. However, the following appended at the end of the supervisor-app.conf does not work:
[program:Xvfb]
command=/usr/bin/Xvfb :1 -screen 0 1024x768x16 &> xvfb.log &
When I open a shell into a running docker instance there is no X instance running:
root#9221694363ea:/# ps aux | grep X
root 39 0.0 0.0 8868 784 ? S+ 15:32 0:00 grep --color=auto X
However, running exactly the same command as in the supervisor-app.conf works
root#9221694363ea:/# /usr/bin/Xvfb :1 -screen 0 1024x768x16 &> xvfb.log &
[1] 40
root#9221694363ea:/# ps aux | grep X
root 40 1.2 0.1 170128 21604 ? Sl 15:33 0:00 /usr/bin/Xvfb :1 -screen 0 1024x768x16
root 48 0.0 0.0 8868 792 ? S+ 15:33 0:00 grep --color=auto X
so what's wrong with the line in the supervisor-app.conf?
Supervisor does not handle bash specific operators such as the-run-in-the -background '&' or redirections like '>' as per my original failing config line.
I solved it by using bash -c thus:
[program:Xvfb]
command=bash -c "/usr/bin/Xvfb :1 -screen 0 1024x768x16 &> xvfb.log"
Now when I get into the docker bash shell the Xvfb window is created waiting for me to use it elsewhere in the code.

Unable to modify files in container from docker

I am attempting to build an imaging by modifying some of the files in an existing image. However, the files are not changed by RUN commands. My dockerfile is
FROM vromero/activemq-artemis
ADD . .
RUN ls
RUN whoami
# Overwrite existing password file. The existing file is invulnerable, and
# cannot be modified by docker. I have no idea why.
RUN rm -f /var/lib/artemis/etc/artemis-users.properties
RUN ls -l /var/lib/artemis/etc
RUN mv passwords.txt /var/lib/artemis/etc/artemis-users.properties
RUN cat /var/lib/artemis/etc/artemis-users.properties
RUN touch /var/lib/artemis/etc/touch-test
# Add the predefined queues
RUN sed -i.bak '/<core/r queues.xml' /var/lib/artemis/etc/broker.xml
# EOF
The base image is from the public docker repository. When I run it, I get the following output
$ docker build .
Sending build context to Docker daemon 4.608 kB
Step 0 : FROM vromero/activemq-artemis
---> 4e0f54c798cc
Step 1 : ADD . .
---> 3efde5a1fdea
Removing intermediate container c8621adc900b
Step 2 : RUN ls
---> Running in 5c5dca9449da
Dockerfile
artemis
artemis-service
passwords.txt
queues.xml
---> 22c541f98339
Removing intermediate container 5c5dca9449da
Step 3 : RUN whoami
---> Running in f11fcd2e2c5b
root
---> 15ee9aeb4c15
Removing intermediate container f11fcd2e2c5b
Step 4 : RUN rm -f /var/lib/artemis/etc/artemis-users.properties
---> Running in ab4383f0bb91
---> 10877bdb08ee
Removing intermediate container ab4383f0bb91
Step 5 : RUN ls -l /var/lib/artemis/etc
---> Running in a5669c8808e8
total 24
-rw-r--r-- 1 artemis artemis 959 Oct 4 05:40 artemis-roles.properties
-rw-r--r-- 1 artemis artemis 968 Oct 4 05:40 artemis-users.properties
-rwxrwxr-x 1 artemis artemis 1342 Oct 4 05:40 artemis.profile
-rw-r--r-- 1 artemis artemis 1302 Oct 4 05:40 bootstrap.xml
-rw-r--r-- 1 artemis artemis 4000 Oct 4 05:40 broker.xml
-rw-r--r-- 1 artemis artemis 2203 Oct 4 05:40 logging.properties
---> 02e3acc58653
Removing intermediate container a5669c8808e8
Step 6 : RUN mv passwords.txt /var/lib/artemis/etc/artemis-users.properties
---> Running in 68000aa34f6b
---> ec057d5adc67
Removing intermediate container 68000aa34f6b
Step 7 : RUN cat /var/lib/artemis/etc/artemis-users.properties
---> Running in 934a36d8c4d1
## ---------------------------------------------------------------------------
## Licensed to the Apache Software Foundation (ASF) under one or more
## contributor license agreements. See the NOTICE file distributed with
## this work for additional information regarding copyright ownership.
## The ASF licenses this file to You under the Apache License, Version 2.0
## (the "License"); you may not use this file except in compliance with
## the License. You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------
apollo=ollopaehcapa ---> ca1bad8a8903
Removing intermediate container 934a36d8c4d1
Step 8 : RUN touch /var/lib/artemis/etc/touch-test
---> Running in cb931c5cfcd1
---> 6961b4fcde75
Removing intermediate container cb931c5cfcd1
Step 9 : RUN sed -i.bak '/<core/r queues.xml' /var/lib/artemis/etc/broker.xml
---> Running in a829642b29ab
---> effd394fc02f
Removing intermediate container a829642b29ab
Successfully built effd394fc02f
The ADD . . has worked, as passwords.txt and queues.xml both show up in the ls. whoami shows that the current user is root, so there should be no permissions problems.
However, the existing files are not changed. If I run the image but use bash as the start command (see below), none of the files have a current date, although the file that was mv'ed to replace an existing file is gone. If I paste the sed command into the shell, it does update the file.
$ docker run -it effd394fc02f bash
root#51d1cc0a94cb:/var/lib/artemis/bin# ls -l
total 16
-rw-r--r-- 1 root root 543 Oct 21 22:12 Dockerfile
-rwxrwxr-x 1 artemis artemis 3416 Oct 4 05:40 artemis
-rwxrwxr-x 1 artemis artemis 3103 Oct 4 05:40 artemis-service
-rw-r--r-- 1 root root 329 Oct 21 22:18 queues.xml
root#51d1cc0a94cb:/var/lib/artemis/bin# cd ../etc
root#51d1cc0a94cb:/var/lib/artemis/etc# ls -l
total 24
-rw-r--r-- 1 artemis artemis 959 Oct 4 05:40 artemis-roles.properties
-rw-r--r-- 1 artemis artemis 968 Oct 4 05:40 artemis-users.properties
-rwxrwxr-x 1 artemis artemis 1342 Oct 4 05:40 artemis.profile
-rw-r--r-- 1 artemis artemis 1302 Oct 4 05:40 bootstrap.xml
-rw-r--r-- 1 artemis artemis 4000 Oct 4 05:40 broker.xml
-rw-r--r-- 1 artemis artemis 2203 Oct 4 05:40 logging.properties
Why are these files not being changed by the run commands?
The actual problem was related to how the base image was built. If you run docker history --no-trunc vromero/activemq-artemis, you see these commands (among others):
<id> 6 weeks ago /bin/sh -c #(nop) VOLUME [/var/lib/artemis/etc] 0 B
<id> 6 weeks ago /bin/sh -c #(nop) VOLUME [/var/lib/artemis/tmp] 0 B
<id> 6 weeks ago /bin/sh -c #(nop) VOLUME [/var/lib/artemis/data] 0 B
The Dockerfile volume documentation states
Note: If any build steps change the data within the volume after it
has been declared, those changes will be discarded.
This means that the configuration in the base image is locked.
I solved my problem by creating my own dockerfile based on the output of the history command, without the volume lines.
Not a complete answer, but at least a clue: you don't change the entrypoint of the built image.
That means your image will still execute the one from vromero/activemq-artemis, which, according to its Dockerfile is:
ENTRYPOINT ["/docker-entrypoint.sh"]
And docker-entrypoint.sh might reset some of your changes on docker run.
There are two RUN commands in Dockerfile.
You are running this: RUN <command> (the command is run in a shell - /bin/sh -c (shell form)
The other one is this: RUN ["executable", "param1", "param2"] (exec form)
Try this:
RUN ["rm", "-f", "/var/lib/artemis/etc/artemis-users.properties"]
RUN ["ls", "-l", "/var/lib/artemis/etc"]
RUN ["mv", "passwords.txt", "/var/lib/artemis/etc/artemis-users.properties"]
RUN ["cat", "/var/lib/artemis/etc/artemis-users.properties"]
RUN ["touch", "/var/lib/artemis/etc/touch-test"]
# Add the predefined queues
RUN ["sed", "-i.bak", "'/<core/r queues.xml'", "/var/lib/artemis/etc/broker.xml"]

Edit apache configuration in docker

First time docker user here, I'm using this image: https://github.com/dgraziotin/osx-docker-lamp
I want to make the apache in that container to use a configuration file from the host system. How do I do that?
I know I can use nsenter, but I think my changes will get deleted when the container is turned off.
Thank you
The best solution is using VOLUME.
docker pull dgraziotin/lamp
You need to copy /etc/apache2/ from container to current directory in host computer. Then you can do this:
cd ~
mkdir conf
docker run -i -t --rm -v ~/conf:/tmp/conf dgraziotin/lamp:latest /bin/bash
On container do:
ls /tmp/conf
cd /etc/apache2/
tar -cf /tmp/conf/apache-conf.tar *
exit
On host computer:
cd conf
tar -xf apache-conf.tar
cd ..
# alter your configuration in this file and save
vi conf/apache2.conf
# run your container : daemon mode
docker run -d -p 9180:80 --name web-01 -v ~/conf:/etc/apache2 dgraziotin/lamp:latest
docker ps
To list conf content on Container use:
docker exec web-01 ls -lAt /etc/apache2/
total 72
-rw-r--r-- 1 root root 1779 Jul 17 20:24 envvars
drwxr-xr-x 2 root root 4096 Apr 10 11:46 mods-enabled
drwxr-xr-x 2 root root 4096 Apr 10 11:45 sites-available
-rw-r--r-- 1 root root 7136 Apr 10 11:45 apache2.conf
drwxr-xr-x 2 root root 4096 Apr 10 11:45 mods-available
drwxr-xr-x 2 root root 4096 Apr 10 11:44 conf-enabled
drwxr-xr-x 2 root root 4096 Apr 10 11:44 sites-enabled
drwxr-xr-x 2 root root 4096 Apr 10 11:44 conf-available
-rw-r--r-- 1 root root 320 Jan 7 2014 ports.conf
-rw-r--r-- 1 root root 31063 Jan 3 2014 magic
Use docker exec web-01 cat /etc/apache2/apache2.conf to list content inside Container.
One the WEB page to test your environment.
I hope this help you.
You should use a Dockerfile to generate a new image containing your desired configuration. For example:
FROM dgraziotin/lamp
COPY my-config-file /some/configuration/file
This assumes that there is a file my-config-file located in the same directory as the Dockerfile. Then run:
docker build -t myimage
And once the build completes you will have an image named myimage available locally.

Resources