The reason why echoing isn't working is that the $TEST environment variable is substituted on your host side. To postpone the substitution to container side, wrap the echo command with single quotes:
docker run --env TEST='xxx' ubuntu:14.04 sh -c 'echo $TEST'