Jump to content

Docker Help

Cowboy Denny

Recommended Posts

Let's touch on a few basics of docker

How to Copy a File from docker image to host

  1. Identify Container ID
    1. [root@usdet1lvdwb002 ~]# docker ps
      CONTAINER ID   IMAGE                      COMMAND                  CREATED        STATUS                 PORTS                                                                                    NAMES
      3feed178f975   portainer/portainer-ce     "/portainer"             4 months ago   Up 3 hours             8000/tcp,>9000/tcp, :::9000->9000/tcp                                      portainer
      8fc045e68c72   librenms/librenms:latest   "/init"                  4 months ago   Up 3 hours   >514/tcp,>514/udp, :::514->514/tcp, :::514->514/udp, 8000/tcp   librenms_syslogng
      5f2591912625   librenms/librenms:latest   "/init"                  4 months ago   Up 3 hours             514/tcp, 8000/tcp, 514/udp                                                               librenms_dispatcher
      768e90e4a2c8   librenms/librenms:latest   "/init"                  4 months ago   Up 3 hours             514/tcp, 514/udp,>8000/tcp, :::8000->8000/tcp                              librenms
      2926209e5c1d   eff629089685               "docker-entrypoint.s…"   4 months ago   Up 3 hours             3306/tcp                                                                                 librenms_db
      51a9b6406a90   crazymax/msmtpd:latest     "/init"                  4 months ago   Up 3 hours (healthy)   2500/tcp                                                                                 librenms_msmtpd
      e17acb99488a   memcached:alpine           "docker-entrypoint.s…"   4 months ago   Up 3 hours             11211/tcp                                                                                librenms_memcached
      896721f9b451   redis:5.0-alpine           "docker-entrypoint.s…"   4 months ago   Up 3 hours             6379/tcp                                                                                 librenms_redis
  2. Copy file (librenms.sql) and this case its on the db container...  you only need to use part of the container ID
    1. docker cp 2926209:/librenms.sql

      It's that easy

How do I SSH into a running container

There is a docker exec command that can be used to connect to a container that is already running. 

  • Use docker ps to get the name of the existing container
  • Use the command docker exec -it <container name> /bin/bash to get a bash shell in the container
  • Generically, use docker exec -it <container name> <command> to execute whatever command you specify in the container.

How do I run a command in my container?

The proper way to run a command in a container is: docker-compose run <container name> <command>. For example, to get a shell into your web container you might run docker-compose run web /bin/bash

To run a series of commands, you must wrap them in a single command using a shell. For example: docker-compose run <name in yml> sh -c '<command 1> && <command 2> && <command 3>'

In some cases you may want to run a container that is not defined by a docker-compose.yml file, for example to test a new container configuration. Use docker run to start a new container with a given image: docker run -it <image name> <command>

The docker run command accepts command line options to specify volume mounts, environment variables, the working directory, and more.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...