I'm going through getting-started tutorial (https://www.docker.com/101-tutorial - Docker Desktop) from docker and they have this docker-compose here:
version: "3.7"
services:
app:
image: node:12-alpine
command: sh -c "yarn install && yarn run dev"
ports:
- 3000:3000
working_dir: /app
volumes:
- ./:/app
environment:
MYSQL_HOST: mysql
MYSQL_USER: root
MYSQL_PASSWORD: secret
MYSQL_DB: todos
mysql:
image: mysql:5.7
volumes:
- todo-mysql-data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: secret
MYSQL_DATABASE: todos
volumes:
todo-mysql-data:
The problem is that MySQL is not creating the "todos" database. And then my application can't connect to it giving me this error:
app_1 | Error: ER_HOST_NOT_PRIVILEGED: Host '172.26.0.2' is not allowed to connect to this MySQL server
app_1 | at Handshake.Sequence._packetToError (/app/node_modules/mysql/lib/protocol/sequences/Sequence.js:47:14)
app_1 | at Handshake.ErrorPacket (/app/node_modules/mysql/lib/protocol/sequences/Handshake.js:123:18)
app_1 | at Protocol._parsePacket (/app/node_modules/mysql/lib/protocol/Protocol.js:291:23)
app_1 | at Parser._parsePacket (/app/node_modules/mysql/lib/protocol/Parser.js:433:10)
app_1 | at Parser.write (/app/node_modules/mysql/lib/protocol/Parser.js:43:10)
app_1 | at Protocol.write (/app/node_modules/mysql/lib/protocol/Protocol.js:38:16)
app_1 | at Socket.<anonymous> (/app/node_modules/mysql/lib/Connection.js:91:28)
app_1 | at Socket.<anonymous> (/app/node_modules/mysql/lib/Connection.js:525:10)
app_1 | at Socket.emit (events.js:310:20)
app_1 | at addChunk (_stream_readable.js:286:12)
app_1 | --------------------
app_1 | at Protocol._enqueue (/app/node_modules/mysql/lib/protocol/Protocol.js:144:48)
app_1 | at Protocol.handshake (/app/node_modules/mysql/lib/protocol/Protocol.js:51:23)
app_1 | at PoolConnection.connect (/app/node_modules/mysql/lib/Connection.js:119:18)
app_1 | at Pool.getConnection (/app/node_modules/mysql/lib/Pool.js:48:16)
app_1 | at Pool.query (/app/node_modules/mysql/lib/Pool.js:202:8)
app_1 | at /app/src/persistence/mysql.js:35:14
app_1 | at new Promise (<anonymous>)
app_1 | at Object.init (/app/src/persistence/mysql.js:34:12)
app_1 | at processTicksAndRejections (internal/process/task_queues.js:97:5) {
app_1 | code: 'ER_HOST_NOT_PRIVILEGED',
app_1 | errno: 1130,
app_1 | sqlMessage: "Host '172.26.0.2' is not allowed to connect to this MySQL server",
app_1 | sqlState: undefined,
app_1 | fatal: true
app_1 | }
If I run this command alone to spin MySQL, the "todos" database is created:
docker run -d --network todo-app --network-alias mysql -v todo-mysql-data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=secret -e MYSQL_DATABASE=todos mysql:5.7
Is there any command that was updated or that doesn't work properly on windows with docker-compose?
Kubernetes, also known as K8s, is an open-source container orchestration tool for automating deployment, scaling, and management of containerized applications. Is Docker hard to learn? If you dedicate your time in learning such crucial skills and practice them accordingly, you could simply learn Docker in 30 days.
Go to performance and then CPU to verify whether Virtualization is enabled or not. If virtualization is disabled Docker Desktop cannot start. If the virtualization is disabled in your machine then you need to enable it from BIOS Settings.
It's easy! Truly, Docker is a time saving tool that is easy to learn and integrate into your environment. There's no reason to avoid learning Docker, as it will benefit almost every server room to some degree. Its Open Source nature also means those benefits can be realized without a large investment.
Run the command
docker-compose down --volumes
to remove any problematic volume created during the tutorial early phases, then, resume your tutorial at the step Running our Application Stack.
I suppose that the tutorial you are following is this one.
If you did follow it piece by piece and tried some docker-compose up -d
in the step 1 or 2, then you've probably created a volume without your todos
database.
Just going docker-compose down
with your existing docker-compose.yml won't suffice because volumes is exactly made for this, the volume is the permanent storage layer of Docker.
By default all files created inside a container are stored on a writable container layer. This means that:
- The data doesn’t persist when that container no longer exists, and it can be difficult to get the data out of the container if another process needs it.
- A container’s writable layer is tightly coupled to the host machine where the container is running. You can’t easily move the data somewhere else.
- Writing into a container’s writable layer requires a storage driver to manage the filesystem. The storage driver provides a union filesystem, using the Linux kernel. This extra abstraction reduces performance as compared to using data volumes, which write directly to the host filesystem.
Docker has two options for containers to store files in the host machine, so that the files are persisted even after the container stops: volumes, and bind mounts. If you’re running Docker on Linux you can also use a tmpfs mount. If you’re running Docker on Windows you can also use a named pipe.
Source: https://docs.docker.com/storage/
In order to remove that volume, you probably created without your database there is an extra flag you can add to docker-compose down
: the flag --volumes
or, in short -v
-v, --volumes Remove named volumes declared in the `volumes`
section of the Compose file and anonymous volumes
attached to containers.
Source: https://docs.docker.com/compose/reference/down/
So your fix should be as simple as:
docker-compose down --volumes
docker-compose up -d
, so back in your tutorial at the step Running our Application Stack
docker-compose logs -f
as prompted in the rest of the tutorialIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With