Miracle
Miracle

Reputation: 81

Docker Compose - Starting already created containers

I am new to Docker and I am trying to run Selenium Grid tests on Docker. For this purpose, I created a docker compose file and executed below command

docker-compose -f docker-compose.yaml up

Everything worked fine but after a few hours I restarted host machine and executed above command again. This time I get below error

ERROR: for selenium-hub  Cannot create container for service selenium-hub: Conflict. The container name "/selenium-hub" is already in use by container "some-hash". You have to remove (or rename) that container to be able to reuse that name.

I tried docker-compose -f docker-compose.yaml run selenium-hub but this command does not start selenium nodes. So my questions are -

Below the Docker-Compose I used

version: "3"
services:
  selenium-hub:
    image: selenium/hub:3.141.59-20200525
    container_name: selenium-hub
    ports:
      - "4444:4444"

  chrome:
    image: selenium/node-chrome:3.141.59-20200525
    volumes:
      - /dev/shm:/dev/shm
    depends_on:
      - selenium-hub
    environment:
      - HUB_HOST=selenium-hub
      - HUB_PORT=4444

  firefox:
    image: selenium/node-firefox:3.141.59-20200525
    volumes:
      - /dev/shm:/dev/shm
    depends_on:
      - selenium-hub
    environment:
      - HUB_HOST=selenium-hub
      - HUB_PORT=4444

  opera:
    image: selenium/node-opera:3.141.59-20200525
    volumes:
      - /dev/shm:/dev/shm
    depends_on:
      - selenium-hub
    environment:
      - HUB_HOST=selenium-hub
      - HUB_PORT=4444

Upvotes: 3

Views: 2057

Answers (2)

aryanveer
aryanveer

Reputation: 666

Just use docker-compose up command to start the already created containers.

Upvotes: -1

user12640668
user12640668

Reputation:

There are possible ways

  1. docker system prune will clean up the cache and remove the dangling intermediate container and delete containers name that not actively running. This command have to be used carefully
  2. docker container prune will delete only dead/stop containers and will free up names
  3. docker rm -v $(docker ps -aq -f 'status=exited')
  4. docker rmi $(docker images -aq -f 'dangling=true')
  5. docker-compose rm --force emoves one-off containers created by docker-compose up or docker-compose run

Upvotes: 3

Related Questions