0

I'm creating docker images using dockerfile-maven-plugin and I want to shell into the container, and I'm getting this error:

OCI runtime exec failed: exec failed: container_linux.go:344: starting container process caused "exec: \"/bin/bash\": stat /bin/bash: no such file or directory": unknown

I've tried:

  • docker exec -it <container_id> /bin/bash
  • docker exec -it <container_id> bash

both with the same result

this is how I'm running the image:

docker run <image_id>

this is how I'm creating the image:

mvn install dockerfile:build

build on pom.xml:

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>

            <plugin>
                <groupId>com.spotify</groupId>
                <artifactId>dockerfile-maven-plugin</artifactId>
                <version>1.4.9</version>
                <configuration>
                    <repository>${docker.image.prefix}/${project.artifactId}</repository>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>unpack</id>
                        <phase>package</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>${project.groupId}</groupId>
                                    <artifactId>${project.artifactId}</artifactId>
                                    <version>${project.version}</version>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                        </execution>
                    </executions>
            </plugin>
        </plugins>
    </build>

I expect to open a shell into the container

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Facundo Laxalde
  • 305
  • 5
  • 18
  • The error is explicit, “bash” doesn’t exist in the container. What is your base image? Post a copy of the Dockerfile you’re building the image from maybe(?). – masseyb Jul 05 '19 at 16:48
  • sure: ``` FROM openjdk:8-jdk-alpine VOLUME /tmp ARG DEPENDENCY=target/dependency COPY ${DEPENDENCY}/BOOT-INF/lib /app/lib COPY ${DEPENDENCY}/META-INF /app/META-INF COPY ${DEPENDENCY}/BOOT-INF/classes /app ENTRYPOINT ["java","-cp","app:app/lib/*","hello.Application"] ``` – Facundo Laxalde Jul 05 '19 at 16:53
  • 1
    should I be able to add this to the original post ? – Facundo Laxalde Jul 05 '19 at 16:53
  • 1
    You should be able to update your question, yes. Ref. your Dockerfile you’re building off an alpine image, they don’t contain bash in most cases, could use e.g. “sh” or “ash”. Check this question for example: https://stackoverflow.com/q/35689628/1423507 – masseyb Jul 05 '19 at 17:00
  • Also, docker exec requires the container that you’re executing the command in, ref. https://docs.docker.com/engine/reference/commandline/exec/ - Usage: docker exec [OPTIONS] CONTAINER COMMAND [ARG...] – masseyb Jul 05 '19 at 17:11
  • @masseyb thanks for your answer, docker run -it --rm 0d73f8db9e99 /bin/ash as suggested in the other question does not work either. any other ideas ? – Facundo Laxalde Jul 05 '19 at 17:18
  • docker exec is to execute a command in an already running container cf. docker run to run a new container instance - if you’re container is running then you should use docker exec -it ... – masseyb Jul 05 '19 at 17:22
  • awesome !! docker exec -it /bin/ash worked. thank you all for your comments. – Facundo Laxalde Jul 05 '19 at 17:31

1 Answers1

0

as I'm building off an alpine image, the correct command is

docker exec -it  <container_id> /bin/ash
Facundo Laxalde
  • 305
  • 5
  • 18