The first option would be to simply store the container ID in a variable.
docker build . -t container:latest
container_id="$(docker run -t -d container /bin/bash)"
docker cp "$container_id":/xyz/xyz.txt /tmp
Docker also allows you to specify a container name.
docker build . -t container:latest
docker run -t --name NAME -d container /bin/bash
docker cp NAME:/xyz/xyz.txt /tmp
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…