Getting error running "podman unshare chown" - containers

I'm trying to run a mysql container with a persistent volume but when I run the command below I got an error guiding to use unshare with rootless:
$podman unshare chown 27:27 -R /home/user1/tmp
Error: please use unshare with rootless

It has been solved using mount option :Z
$ podman run container -v /local/dir:/container/dir:Z -d image:latest

Related

Resuming docker mysql instance after restarting

I'm using docker to run a mysql 5.6 instance on my localhost (which is running ubuntu 20.04), using these instructions. When I create a new container for the database I use the following command
sudo docker run --name mysql-56-container -p 127.0.0.1:3310:3306 -e MYSQL_ROOT_PASSWORD=rootpassword -d mysql:5.6
That serves the intended purpose; I'm able to create the database using port 3310 and get on with what I want to do.
However when I reboot my localhost, I am unable to get back into sql5.6 using that port again.
When I list containers, I see none listed:
$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
So I try to recreate it and am told that it already exists:
$ sudo docker run --name mysql-56-container -p 127.0.0.1:3310:3306 -e MYSQL_ROOT_PASSWORD=rootpassword -d mysql:5.6
docker: Error response from daemon: Conflict. The container name "/mysql-56-container" is already in use by container "a05582bff8fc02da37929d2fa2bba2e13c3b9eb488fa03fcffb09348dffd858f". You have to remove (or rename) that container to be able to reuse that name.
See 'docker run --help'.
So I try starting it but with no luck:
$ sudo docker start my-56-container
Error response from daemon: No such container: my-56-container
Error: failed to start containers: my-56-container
I clearly am not understanding how this works so my question is, how do I resume work on databases I've created in a docker container after I reboot?
docker ps just list running containers. If you reboot your laptop, all of them will be stopped. You can use docker ps --all or docker container ls --all to list all containers (running or stopped). You can check more about the docker ps command in docker ps command line reference
Once a container is created, you cannot create another with the same name. Tha is the reason your second docker run is failing.
You should use docker start instead. But you are trying to start a container with a different name. Your docker start command is using a container named my-56-container but it is called mysql-56-container. Please check your first docker run command in the question.

Command to use with scratch docker container

I'm trying to start a docker container for mysql. The image for the container was built from scratch for a training I attended and I need to figure out how to configure it to run a command that will start the container.
The /bin/bash and /bin/sh commands don't work. When I docker inspect the container the CMD section doesn't contain anything. I've tried running CMD['/bin/bash'] or CMD['/bin/sh'] at the end of my docker container run command and that populates the CMD field but the container still won't run.
There are a number of other microservice containers I'm having the same problem with. This is the first one I need to solve however.
This is the command I'm running:
docker run -d -v infytel-mysql-volume:/var/lib/mysql --network=infytel-docker-networkMS --name=infytel-mysql-con2 -e MYSQL_PASSWORD_ROOT=root infytel-mysql-img:v1 /bin/bash
This is my error:
oci runtime error: container_linux.go:235: starting container process caused "exec: \"/bin/bash\": stat /bin/bash: no such file or directory
[EDIT] Running docker logs gives the error shown above.
Running without the /bin/sh command states error response from daemon: No command specified

docker: invalid reference format. See 'docker run --help'

I am trying to serving my model using TensorFlow with docker. I downloaded Docker for windows and tried the code as per the documentation.
!docker pull tensorflow/serving
!git clone https://github.com/tensorflow/serving
TESTDATA="/serving/tensorflow_serving/servables/tensorflow/testdata"
Above code worked fine .But when i tried below code
!docker run -t --rm -p 8501:8501,-v "TESTDATA/saved_model_half_plus_two_cpu:/models/half_plus_two",-e MODEL_NAME=half_plus_two,tensorflow/serving
It is giving below error.
docker: invalid reference format.See 'docker run --help'..
Any idea guys please help.
#BSP This worked for me:
docker run -t --rm -p 8501:8501 -v "$testdata/saved_model_half_plus_two_cpu:/models/half_plus_two" -e "MODEL_NAME=half_plus_two" tensorflow/serving

Docker container bash terminal is irresponsive

I have a MySQL instance running on a docker container. I am trying to access the bash terminal by running "docker exec -t myContainerID /bin/bash" for the container so that I can check into my MySQL and see if the setup is correct. Although after accessing the bash terminal, any command I run is irresponsive. Even something as simple as ls. Is there any way to resolve this or know what might be causing the problem? Thanks.
You seem to be missing the -i option, try running: docker exec -ti CONTAINER_ID /bin/bash
And just FYI:
--interactive , -i Keep STDIN open even if not attached
--tty , -t Allocate a pseudo-TTY

install mysql in docker and expose mysql service to outside

I am learning docker these days. And I want to install mysql inside docker container.
Here is my Dockerfile
FROM ubuntu:14.04
ADD ./setup_mysql.sh /setup_mysql.sh
RUN chmod 755 /setup_mysql.sh
RUN /setup_mysql.sh
EXPOSE 3306
CMD ["/usr/sbin/mysqld"]
and shell script setup_mysql.sh
apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y mysql-server
sed -i -e "s/^bind-address\s*=\s*127.0.0.1/bind-address = 0.0.0.0/" /etc/mysql/my.cnf
service mysql start &
sleep 5
echo "UPDATE mysql.user SET password=PASSWORD('rootpass') WHERE user='root'" | mysql
echo "CREATE DATABASE devdb" | mysql
echo "GRANT ALL ON devdb.* TO devuser #'%' IDENTIFIED BY 'devpass'" | mysql
sleep 5
service mysql stop
Something wrong happend when running sudo docker build -t test/devenv .
Setting up mysql-server-5.5 (5.5.38-0ubuntu0.14.04.1) ...
invoke-rc.d: policy-rc.d denied execution of stop.
invoke-rc.d: policy-rc.d denied execution of start.
And if I remove the second sleep 5, the command service mysql stop will throw
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
Why does this happen?
Thank you!
I high recommend leveraging the work of others. For example checkout the Mysql image from the docker registry:
https://registry.hub.docker.com/_/mysql/
Here's the associated git repository files:
https://github.com/docker-library/mysql/blob/master/5.7
If you look into the Dockerfile you'll notice the software is being installed as expected:
.. apt-get update && apt-get install -y mysql-server="${MYSQL_VERSION}"* ..
The trick is to realize that a database instance is not the same thing as the database software, only the latter is shipped with the image. Creating DBs and loading them with data is something that is done at run-time. So that work is done by an extra script, pulled into the image and setup to be executed when you run the container:
COPY docker-entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
Hope this helps.
Add this to your dockerfile:
RUN su
RUN echo exit 0 > /usr/sbin/policy-rc.d
I was facing the same issue. This code fixed it.
Here is a good post which tries to root cause the issue you are facing.
Shorter way:
RUN echo "#!/bin/sh\nexit 0" > /usr/sbin/policy-rc.d should resolve your issue
OR
If that doesn't resolve the issue, try running your docker container with privileged option. Like this, docker run --privileged -d -ti DOCKER_IMAGE:TAG
Ideally, I would not recommend running container with privileged option unless its a test bed container. The reason being running a docker container with privileged gives all capabilities to the container, and it also lifts all the limitations enforced. In other words, the container can then do almost everything that the host can do. But this is not a good practice. This defeats the docker purpose of isolating from host machine.
The ideal way to do this is to set capabilities of your docker container based on what you want to achieve. Googling this should help you out to provide appropriate capability for your docker container.