0

I want to create python + mysql service for simple development environment and download some information from internet.

I don't want to create new build every time, therefore I want to use bind mount for python source code.

My catalog is: 'python_mysql'.

I created there: docker-compose.yml

    version: '3.6'

    services: 
      python:
        image: python:latest
        ports:
         - '80:80'
        volumes:
          - type: bind
            source: .
            target: /scripts
      mysql:
        image: mysql/mysql-server:latest
        volumes:
          - type: volume
            source: mysql-db1
            target: /var/lib/mysql


    volumes: 
      mysql-db1:

I have named volume also - database file : mysql-db1 - i want to used it.

    $ docker volume ls 
    DRIVER              VOLUME NAME
    local               mysql-db1

After:

    $ docker-compose up -d
    Creating network "python_mysql_default" with the default driver
    Creating python_mysql_mysql_1  ... done
    Creating python_mysql_python_1 ... done

have:

    $ docker container ls -a

https://gyazo.com/b355c686db87ef0bfabbffad0ee19b37

    $ docker volume ls 
    DRIVER              VOLUME NAME
    local               mysql-db1
    local               python_mysql_mysql-db1

1) How to use the mysql-db1, not create new one ?

2) How to start python with bash command ? I want interact / go into python container and make something. It is possible without creating dockerfile ?

3) Whether bind mount is done well ?

4) Why in python container I don't see ports 80:80 ? Will the python container have an internet connection via 'request' module?

5) I dont understand top level 'volumes:' command. Can anyone explain to me on the basis of my example?

4
  • What do you mean by Why in python container I don't see ports 80:80? Commented Jul 4, 2018 at 9:45
  • $ docker container ls -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1ad46f892ce1 python:latest "python3" 5 seconds ago Exited (0) 6 seconds ago python_mysql_python_1 PORTS is empty please see link Commented Jul 4, 2018 at 9:49
  • 1
    That is because your container exited, so no more port mapping as the container is not alive any more Commented Jul 4, 2018 at 9:51
  • ok, so this is answer for 4) - thanks. So i want to keep them alive. Best solution for me would be run python with bash command Commented Jul 4, 2018 at 9:55

1 Answer 1

1

1) How to use the mysql-db1, not create new one ?

It will only be created only once until unless you delete it using docker-compose down -v or some other command. So if it doesn't exist it is created

2) How to start python with bash command ? I want interact / go into python container and make something. It is possible without creating dockerfile ?

You need to launch a command which doesn't end without user input. The default python command will exit without the same. So you need to probably a command like

command: tail -f /dev/null

And then later use below command to launch python or bash

docker-compose exec python python

or

docker-compose exec bash

3) Whether bind mount is done well ?

Not sure what it means, but it looks good if it works

4) Why in python container I don't see ports 80:80 ? Will the python container have an internet connection via 'request' module?

You container exited that is why 80:80 is not show

5) I dont understand top level 'volumes:' command. Can anyone explain to me on the basis of my example?

It is to specify the volumes your compose file use. Like mysql-db1, you can control parameters about the same. You can say external: true which means your composition expects a volume to be already present and wont create it and you can even specify which plugin to use for volume. If you use the same

Sign up to request clarification or add additional context in comments.

5 Comments

After your tips, my file looks like this: gyazo.com/dfbb8b617898a1885a33e1198f759e6e Unfortunately, I can not connect to the database. What could be wrong? gyazo.com/db1c2253a6c3965c62485a8d3fecaaf8 mysql.connector.errors.DatabaseError: 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111)
You should use mysql instead of 127.0.0.1
gyazo.com/bf02c0acf1405a15f9f4cdaead563d2a mysql or python_mysql_mysql_1 unfortunately, the problem is still there mysql.connector.errors.DatabaseError: 1130 (HY000): Host '172.18.0.2' is not allowed to connect to this MySQL server. $ docker network inspect python_mysql_default gyazo.com/41770522f781f90e0a2c5fefe6dc66e0
You not defining some required environment variables in your docker-compose. You need to define MYSQL_ROOT_PASSWORD and set the value is ROOT. I think you DB is either not getting up or generating a RANDOM password
I have set MYSQL_ROOT_PASSWORD I can get to the base using docker-compose exec mysql mysql -uroot -proot

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.