0
**[root@ansiblecontrolnode dockerbuild]# docker images**

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

**[root@ansiblecontrolnode dockerbuild]# docker ps -a**

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

[root@ansiblecontrolnode dockerbuild]# cat build_docker_container.yml
---
        - name: Create a data container
          hosts: localhost
          gather_facts: no
          tasks:
                - name: Downloading "ubuntu" image and spinning up a container from same image
                  docker_container:
                        name: container-created-by-ansible
                        image: ubuntu
                        volumes:
                                - /data
...

**[root@ansiblecontrolnode dockerbuild]# ansible-playbook build_docker_container.yml**

PLAY [Create a data container] ******************************************************************************************************************************************************************

TASK [Downloading "ubuntu" image and spinning up a container from same image] *******************************************************************************************************************
changed: [localhost]

PLAY RECAP **************************************************************************************************************************************************************************************
localhost                  : ok=1    changed=1    unreachable=0    failed=0

**[root@ansiblecontrolnode dockerbuild]# docker images**

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

ubuntu              latest              452a96d81c30        5 weeks ago         79.6MB

**[root@ansiblecontrolnode dockerbuild]# docker ps -a**

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES

36161bcee5bc        ubuntu              "/bin/bash"         13 seconds ago      Exited (0) 11 seconds ago                       container-created-by-ansible

**[root@ansiblecontrolnode dockerbuild]# docker start 36161bcee5bc**

36161bcee5bc

**[root@ansiblecontrolnode dockerbuild]# docker attach 36161bcee5bc**

You cannot attach to a stopped container, start it first

**[root@ansiblecontrolnode dockerbuild]# docker ps -a**

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES

36161bcee5bc        ubuntu              "/bin/bash"         35 seconds ago      Exited (0) 11 seconds ago                       container-created-by-ansible

Question - Why I am not able to get into this container?

3
  • It looks like container started (and stopped as well) and that is why you cannot "get into" your container.
    – alexus
    Jun 4, 2018 at 20:42
  • Right Alexus. but we can start the stopped container. Jun 6, 2018 at 11:43
  • Have you tried docker logs CONTAINER_ID?
    – ALex_hha
    Jul 30, 2018 at 18:53

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.