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
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.
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.