How to attach a volume to a Bluemix container - containers

I’m setting up a container on Bluemix using ice from the command line, but every time I try to attach a volume to a container it simply doesn’t work. The mounted folder isn't created in the root directory.
My command is:
ice create -p 80 -p 22 --name test --memory 1024 --volume notebooks:/notebooks registry.ng.bluemix.net/repository/app:latest

Docker gives you the option to create the volume yourself or allow Docker to create it for you. Either one of these will work:
docker run --name mysql_test -v /etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=my-secret-pw -d jw_mysql:latest
OR
docker run --name mysql_test -v /my/custom:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=my-secret-pw -d jw_mysql:latest
For IBM Containers, the situation is different: you need to create a volume before you can use it. So only this will work:
cf ic volume create dbstorage
cf ic run -p 3306 --name cf_mysql_test -v dbstorage:/etc/mysql/config/conf.d -e MYSQL_ROOT_PASSWORD=my-secret-pw -d registry.ng.bluemix.net/jw_image_reg/jw_mysql:latest
(Assuming you want to use port 3306.)

Related

MySQL data directory stays default with -v flag in docker image

I am trying to start MySQL using docker image, I wanted to have a look at the binlog files, however I couldn't find them in /var/lib/mysql. From a few stackoverflow and Google reads, potential reason could be that mysql doesn't have permissions to write in /var/lib/mysql.
So I tried providing a different path using -v flag while starting the docker using the command docker run -it --rm --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=debezium -e MYSQL_USER=mysqluser -e MYSQL_PASSWORD=mysqlpw -v /home/username/mysql debezium/example-mysql:1.1
However, even after this, datadir variable in client still remains /var/lib/mysql. Can someone help me in this?
Using docker run -it --rm --name mysqlterm --link mysql --rm mysql:5.7 sh -c 'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -uroot -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD" to start the MySQL client.
You are running client on different container and expect yo find logs there?
if you want see log files, you should run docker exec mysql bash, sometimes bash is not available, then use sh.

Connecting wordpress container t a multi database container

I'm required to build a multi-database MySQL container, this was straight forward as I followed this tutorial: https://dzone.com/articles/multiple-mysql-databases-with-one-mysql-container
Now I have to run my wordpress container and connect it to one of these databases, I tried what I already know:
docker run -e WORDPRESS_DB_PASSWORD=pass --network wordpress --name wordpress --link mysqldb:mysql -p 4123:80 -v "$PWD/html":/var/www/html -d wordpress
where mysqldb is the container's name but with no luck whatsoever.
What is the proper syntax to link wordpress container with one of these databases? They are two, the other one should be used for another purpose.
I don't have the liberty to use two MySQL containers, any advice is highly appreciated, thanks.
the name when you linked mysqldb:mysql is the database server hostname. In your sample, it is mysql
You can cat /etc/hosts to confirm the mysql hostname in your application container wordpress
Second, you don't have to build a seperate multi-database containers, you just link several times.
# create first mysql database container.
$ docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql
4914c6fbb3e870b530fc5713908cd918ad3d1c43ebbeb460b878857328934f95
# create second mysql database container.
$ docker run --name some-mysql2 -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql
72090be34a5d62ea53edd87e4b513ad5c0c413fe8b223fe36c2aae6938fd77c4
# run your application with links
$ docker run -d --name wordpress --link some-mysql:mysql1 --link some-mysql2:mysql2 wordpress
f1d6fbc2fcf30862efd0a4a4882425e359a2442c1476c0256c338e80a46ae66d
You can check the hostname in wordpress container
$ docker exec -ti f1 bash
root#f1d6fbc2fcf3:/var/www/html# cat /etc/hosts
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.2 mysql1 4914c6fbb3e8 some-mysql # <= here is the first mysql hostname
172.17.0.3 mysql2 72090be34a5d some-mysql2 # <= here is the second mysql hostname
172.17.0.4 f1d6fbc2fcf3
root#f1d6fbc2fcf3:/var/www/html#

Docker create volume for MySQL

I'm starting to use docker implement mysql in our environment. But I have a little bit confuse about it.
1. I have tried to use command, it's working
sudo docker run --name mysql5.7 --restart always --privileged=true -p 4306:3006 -v /Users/user/mysql/config/mysqld.cnf:/etc/mysql/mysql.conf.d/mysqld.cnf -v /Users/user/mysql/data:/var/lib/mysql -e MYSQL_USER=“usr” -e MYSQL_PASSWORD=“1234” -e MYSQL_ROOT_PASSWORD=“1234” -d mysql:5.7
But follow docker document, they suggest use volume to persist data. So I tried crate a volume first docker volume -d create local mysql_v
try to link mysql to volume mysql_v, but I don't know how to do it and what is different with step 1.
anyone can suggest it ~?
Like
docker run --name mysql5.7 --restart always -p 4306:3006 \
-v /Users/user/mysql/config/mysqld.cnf:/etc/mysql/mysql.conf.d/mysqld.cnf \
-v mysql_v:/var/lib/mysql \
-e MYSQL_USER=“usr” -e MYSQL_PASSWORD=“1234” \
-e MYSQL_ROOT_PASSWORD=“1234” -d mysql:5.7
Note, privileged removed, that's just asking for trouble
Ref: official documents

"docker container run" requires at least 1 argument

I'm trying to create a container using a volume that I have already created, but my console shows the error
docker container run" requires at least 1 argument
This is the command I'm trying to run:
docker container run --name db -v volume-dados-do-banco:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=Mypass
I have also tried this one, wih more arguments, but the same error persists:
docker container run -d --name db -p 3306:3306 -e 'ACCEPT_EULA=Y' -e MYSQL_ROOT_PASSWORD=Mypass -v volume-dados-do-banco:/var/lib/mysql
Any thoughts on the reason why this is happening?
Problem is not with docker, you just didn't specify which image to run. Your command should include Docker image as per documentation.
docker run [OPTIONS] IMAGE[:TAG|#DIGEST] [COMMAND] [ARG...]
Example would be:
docker run -d --name db -v volume-dados-do-banco:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=Mypass mysql:latest
i just had the same problem with psql my password simply contained & and i needed to escape it with / before &
try the below command.. it seems a syntax error on your command..
docker container run -d --name db -v volume-dados-do-banco:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=Mypass
i have the same problem when i use this:
docker run -d -p 3306:3306 -v /Volumes/wd4black/mysql -e MYSQL_ROOT_PASSWORD=root mysql
but when i try below, the problem is disappear:
docker run --name my-s -d -p 3306:3306 -v /Volumes/wd4black/mysql -e MYSQL_ROOT_PASSWORD=root mysql
so i think the --name is key, but the doc didn/t write it.
I just restarted docker and ran:
docker run --name torgmysqldb --volumes-from volume-dados-banco-mysql -e MYSQL_ROOT_PASSWORD=Mypass -p 3307:3306 mysql
I found out a known issue about this:
https://github.com/docker/for-win/issues/2722
After you have extracted the image from the Docker repository, you can move on to deploying the new Container with the following code snippet:
sudo docker run --name=[container_name] -d [image_tag_name]

Accessing local MySQL server from my docker container

I have a mysql server and a docker container running on my machine. In the docker container, I run a django website. I want to connect to the local mysql server from the docker container. How can I do that?
I usually do ( for testing purposes ) :
docker network create -d my-bridge
docker run --network my-bridge --name app-db -e MYSQL_ROOT_PASSWORD=secret -e
MYSQL_DATABASE=myapp -e MYSQL_USER=myapp_user -e MYSQL_PASSWORD=myapp_secret
mysql:latest
docker run --network my-bridge --name app -p 80:80 -e DB_HOST=app-db -e DB_USER=myapp_user -e DB_PASS=myapp_secret -e DB_NAME=myapp myapp:latest
In my app Dockefile I am using in entrypoint something like envsubst, or if code language can read from environment variables I dont need to setup this.
Forget about --link docker parameter -> its obsolete