Store `docker run` command output in BASH variable

I’m having an issue storing the output of docker run -it -d -p 43211:3000 --name appname -h hostname -v $PWD/local_dir:/root/remote_dir repo/imagename in a BASH varibale. I tried `backticks`, I also tried running it like the official docs say BASH_VAR=$(docker run ...), I even tried storing the output in a file with docker run --...>$FILE_DESCRIPTOR, but no luck storing the error situation, the situation when the name is already used by another container, like so:

$ FATA[0000] Error response from daemon: Conflict. The name "appname" is already in use by container 7c84d8d703c8. You have to delete (or rename) that container to be able to reuse that name.

  • Can't run any docker commands - timeout
  • How to use docker run with a Meteor image?
  • Dockerfile 'RUN git clone' removes intermediate container
  • Docker integration in OpenShift
  • run vlc in a Docker image to send a video stream via rtsp protocol
  • How to access Docker containers from within a Vagrant VM
  • I want to say that it works for the success situation, so I’m able to store in BASH_VAR the full container ID, upon running the application successfully, but unfortunately this solves only half the problem I’m facing.

    Any help would be appreciated.

    Thanks!

  • Maven's Lifecycle in Dockerfile
  • How to disable password login through ssh for root, while allowing certificate based login
  • Unable to install docker on a fresh debian 8 jessie
  • Boot2Docker searching for docker-bootstrap.sock which does not exist
  • Rancher Container Utilization stats stuck on Connecting
  • How to deploy a Play 2.5 app on Jelastic with Docker?
  • Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.