This is an old revision of the document!
Overview
In order to connect to docker, you should firstly know the name of the docker container. This can be obtained as follows:
[root@tain-cx-uatdkrdb1 ~]# docker container ls CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 71e7c7016763 docker-registry.tain.com/cassandra:3.10 "/docker-entrypoint.…" 9 days ago Up 9 days cas3 ea9b9f22c874 docker-registry.tain.com/cassandra:3.10 "/docker-entrypoint.…" 9 days ago Up 9 days cas2 46fac822cffe docker-registry.tain.com/cassandra:3.10 "/docker-entrypoint.…" 9 days ago Up 9 days cas1
So in order to connect we can simply execute the /bin/bash on the container:
[root@tain-cx-uatdkrdb1 ~]# docker exec --help Usage: docker exec [OPTIONS] CONTAINER COMMAND [ARG...] Run a command in a running container Options: -d, --detach Detached mode: run command in the background --detach-keys string Override the key sequence for detaching a container -e, --env list Set environment variables -i, --interactive Keep STDIN open even if not attached --privileged Give extended privileges to the command -t, --tty Allocate a pseudo-TTY -u, --user string Username or UID (format: <name|uid>[:<group|gid>]) -w, --workdir string Working directory inside the container [root@tain-cx-uatdkrdb1 ~]# docker exec -it cas1 /bin/bash root@46fac822cffe:/# <- We are on 1st container :)
File Migration with Mongo
Migration to and from the docker is done rather easily, even when you have to export a database or so:
Export collection
The export from Mongo is done via the standard utils like: mongoexport, but firstly we have to see our container:
[root@tpb-mts-stdkr1 ~]# docker container ls CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 0ac74afee7b7 nginx:latest "nginx -g 'daemon of…" 7 weeks ago Up 7 weeks 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp production_nginx_1 c188736759e9 docker.tain.com/incident.backend:latest "./server" 7 weeks ago Up 33 hours 0.0.0.0:3000->8080/tcp production_incidenttool_backend_1 18e980dee75c docker.tain.com/incident.frontend:latest "nginx -g 'daemon of…" 7 weeks ago Up 33 hours 0.0.0.0:8080->80/tcp production_incidenttool_frontend_1 8385665052a3 mongo "docker-entrypoint.s…" 4 months ago Up 33 hours 0.0.0.0:27017->27017/tcp production_incidenttool_mongo_1 e03d9bc636c5 mongo "docker-entrypoint.s…" 5 months ago Up 33 hours 0.0.0.0:27018->27017/tcp recordingtool_mongo_1 e4031dbf6b08 mongo-express "tini -- /docker-ent…" 5 months ago Up 33 hours 0.0.0.0:8082->8081/tcp recordingtool_mongo_management_1 667870179b38 recordingtool/server:latest "./server" 5 months ago Up 33 hours recordingtool_server_1 5d37f142d32b netdata/netdata "/usr/sbin/run.sh" 8 months ago Up 27 hours 0.0.0.0:19999->19999/tcp netdata (reverse-i-search)`': ^C
Then we can connect to it as follows:
[root@tpb-mts-stdkr1 ~]# docker exec -it 8385665052a3 /bin/bash
And then we can connect to the mongo, if we want to:
root@8385665052a3:/# mongo admin -u root -p password MongoDB shell version v4.0.4 connecting to: mongodb://127.0.0.1:27017/admin Implicit session: session { "id" : UUID("310e30d1-8cf6-4e4a-b1a4-206d3c9104a1") } MongoDB server version: 4.0.4 Server has startup warnings: 2020-01-09T01:33:38.696+0000 I CONTROL [initandlisten] 2020-01-09T01:33:38.696+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. 2020-01-09T01:33:38.696+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never' 2020-01-09T01:33:38.696+0000 I CONTROL [initandlisten] 2020-01-09T01:33:38.696+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. 2020-01-09T01:33:38.696+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never' 2020-01-09T01:33:38.696+0000 I CONTROL [initandlisten] --- Enable MongoDB's free cloud-based monitoring service, which will then receive and display metrics about your deployment (disk utilization, CPU, operation statistics, etc). The monitoring data will be available on a MongoDB website with a unique URL accessible to you and anyone you share the URL with. MongoDB may use this information to make product improvements and to suggest MongoDB products and deployment options to you. To enable free monitoring, run the following command: db.enableFreeMonitoring() To permanently disable this reminder, run the following command: db.disableFreeMonitoring() --- >