docker-compose no such service: myapp

I've run an image with: 'docker-compose up'

With 'docker ps' i get:

CREATED             STATUS              PORTS                    NAMES
55e1fd18acf1        simpleappnodedocker_web   "node app.js"            6 seconds ago       Up 6 seconds        0.0.0.0:9000->3000/tcp   myapp
9879ff20e241        postgres:9.6              "docker-entrypoint..."   36 hours ago        Up 36 hours         0.0.0.0:5432->5432/tcp   nd-db

I try run the bash to enter to the shell, but i get an error, how to solve this, i thinking i'm doing something wrong.

$docker-compose run myapp /bin/bash   
ERROR: No such service: myapp

docker-compose.yml:

version: '2'
services:
  web:
    container_name: myapp
    build: .
    command: node app.js
    ports:
      - "9000:3000"

I think you got the relation of docker and docker-compose wrong:

docker-compose is a wrapper around docker. To do its job docker-compose needs its config: docker-compose.yaml

Spinning your example further:

create docker-compose.yaml:

version: '2'
services:
  web:
    container_name: myapp
    build: .
    command: node app.js
    ports:
      - "9000:3000"

use docker-compose to start the container and run a command in the running container:

docker-compose up
docker-compose exec web /bin/bash

docker-compose uses the name of the service - in your case this is web - whereas docker uses the container name - in this case myapp.

So to run /bin/bash through docker, you would use the following:

docker exec -ti myapp /bin/bash

you could remove the container_name from docker-compose.yaml, then the container would be named automatically by docker-compose - similar to the service, but prefixed with the name of the docker-compose stack (the foldername where docker-compose.yaml is located).

The other answer is right but somehow was a bit confusing in its broad explanation on "the relation of docker and docker-compose".

The main thing to get rid of the error in question is to do what the error says: "ERROR: No such service:", therefore, you must choose a service that is in your compose file, and not the container name. In the example, it is web, and NOT myapp.

In your case, do not run

docker-compose run --rm myapp bash

but run

docker-compose run --rm web bash

Also make sure you're running the command in the same folder than your docker-compose.yml, otherwise you'll get the same error message but Phillip's answer above won't work.

you are very definitely doing something wrong. To help you, I would need to know what you did and how you did it. Please post your docker-compose.yaml and a complete recall of all your steps.

it’s working with: docker exec -it myapp /bin/bash

@Phillip-ZyanKLee-Stockmann you have the yml config, but really need use docker-compose run, if i can do it with docker run?

nope, you don’t. but it is a great tool to have the config in a git repo for example

so, where is the erro?

Ahh, now I get it, I think. I’ll post an answer.