How to run a container

Screen Shot 2016-10-07 at 4.09.45 PM.png

    1. $ docker run repository/(imageName):tag any-command-to-run-when-spun-up
      1. Creates the container, spins it up and runs it
      2. :1.24 → how you specify a version of the image
      3. Example: $ docker run busybox:1.24 echo “hello world”
      4. Example2: $ docker run busybox:1.24 ls /dev (list files in /dev)
      5. Above command puts you inside containers console.
        1. To free up console, run -d flag (“detached” mode)

Flags - Runs container w/specified parameters

    1. Interactive
      1. -i → interactive
      2. -t → creates psuedo TTY with stdin & stdout
          1. TTY = TeleType Writer (originally for deaf people) tele comes from a Greek root meaning far or distant. TTY's provide a virtual interface similar to what the physical machines provided. This is the origin of the 80 char width and carriage return
        • Example: $ docker run -t -i busybox:1.24
          1. Gives you terminal inside the container. Prompt looks like / #
          2. Exit terminal in container

/ # exit → exits terminal & SHUT DOWN CONTAINER

    1. Detached
      1. -d → detached mode. Frees up console
    2. Interactive mode
      1. $ docker exec -it <cont_id> command
        1. exec lets you run a command inside a running container
          1. -it → enter container in interactive mode
          2. bash → command (enter bash mode)
        2. To enter detached container once running …
        3. Example → $ docker exec -it 175cfac1b48a bash
        4. See Running programs → $ ps axu (just a shell command)
        5. Exit interactive mode (& return to daemon mode) → ctrl-p & ctrl-q

“Hitting” IP address of a container

      1. We linked external port to the DM’s internal port when we created the container
      2. docker run -p 8080:3000 imageName - (machine port:container port)

(DM external port:DM internal port)

        1. $ docker-machine ls to get ip of docker_host environment
        2. $ docker ps to get ip of specific container
          1. dockerapp_1 | * Running on http://0.0.0.0:5000/

This is the ip WITHIN container. Need to get to where container is running (which is the ip of docker_host)

          1. Therefore ip of running container is:

Docker_host_ip:external port exposed by container

Examples of finding docker_host IP:container_external_port

        1. Node example → $ docker run -p 8080:3000 node
          1. Remember, whale icon: “docker is configured to use the default machine with IP 192.168.99.100”. This is host ip
          2. Port can be ‘hit’ outside linux VM at this ip + port #
          3. Can hit port within Linux VM at http://localhost:3000
          4. To hit port from outside the Linux VM, we set external port to 8080 so container will export on Linux VM’s ip address on port 8080 http://192.168.99.100:8080
        2. Tomcat example → $ docker run -p 8888:8080 tomcat:8.0
          1. http://host-ip:8888

$ docker-machine ls → Lists DMs & host-ip

results matching ""

    No results matching ""